note 82885 deleted from language.references.pass by danbrown

From: Date: Thu, 28 Jan 2010 13:18:03 +0000
Subject: note 82885 deleted from language.references.pass by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-165413@lists.php.net to get a copy of this message
Note Submitter: madmax ---- Passing by Reference Issues: <?php # sample function: function foo(&$var) { $var++; } # this works: $a = 1; foo($b = 1); print_r($a . '<br>'); // 1 print_r($b . '<br>'); // 2 # this produces a error: $a = 1; foo($b = $a); // create a copy of a print_r($a . '<br>'); // should be 1 print_r($b . '<br>'); // should be 2 # this works: $a = 1; foo($b = (int)$a); print_r($a . '<br>'); // 1 print_r($b . '<br>'); // 2 # if you want to pass a copy of a array use this function: foo($b = DeRef($a)); // create a copy of $a function &DeRef($var) { return($var); } ?> can someone explain why foo($b = $a) is not valid ?

« previous php.notes (#165413) next »