Re: unsetting a referenced parameter in a function
| From: | Shawn McKenzie | Date: | Wed, 22 Jul 2009 22:09:26 +0000 |
| Subject: | Re: unsetting a referenced parameter in a function | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-295719@lists.php.net to get a copy of this message | ||
Tom Worster wrote:
> 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.
>
>
Well, you unset the reference and then you assigned 'meaning' to a local
function variable $a. Why would you get a compile error?
--
Thanks!
-Shawn
http://www.spidean.com