PHP - Make reference parameter optional? -


say i've defined function in php, , last parameter passed reference. there way can make optional? how can tell if it's set?

i've never worked pass-by-reference in php, there may goofy mistake below, here's example:

$foo; function bar($var1,&$reference) {     if(isset($reference)) do_stuff();     else return false; }  bar("variable");//reference not set bar("variable",$foo);//reference set 

taken php official manual:

null can used default value, can not passed outside

<?php  function foo(&$a = null) {     if ($a === null) {         echo "null\n";     } else {         echo "$a\n";     } }  foo(); // "null"  foo($uninitialized_var); // "null"  $var = "hello world"; foo($var); // "hello world"  foo(5); // produces error  foo(null); // produces error  ?> 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -