unsetting a referenced parameter in a function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



though the manual is perfectly clear that this should be expected, i was a
bit surprised that the result of the following is 42

<?php
function foo(&$a) {
  $a = 42;
  unset($a);
  $a = 'meaning';
}
foo($a);
print("$a\n");
?>

normally i would expect unset() to free some memory. but in this example it
doesn't and has a different behavior: it releases foo's reference to the
global $a, allowing the next line to define a local $a.

i think i'd have preferred compile error.



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux