RE: [PHP] assignment by reference bug? (update)
| From: | reynardmh at netscape dot net | Date: | Sun, 22 Dec 2002 03:43:45 +0000 |
| Subject: | RE: [PHP] assignment by reference bug? (update) | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-129095@lists.php.net to get a copy of this message | ||
just a little update after playing arround with this stuffs,
I think this behavior happens when there is nothing else pointing to variable $a.
so for example, this works also:
$tmp =& $a;
$a =& $a->next;
I'm wondering how php does garbage collection? does it immediately delete variables that have
nothing pointing to it?
- reynard
>hi,
>
>I just found this behavior when trying to implement a linked list with php.
>In linked list it's common to say:
>$a =& $a->next;
>when traversing the list. but this doesn't work (it gives segmentation fault when trying to
>access the $head->next object (after the above assignment).
>but this work:
>
>$tmp =& $a;
>$a =& $tmp->next;
>
>I don't know if this can be considered a bug or if it's designed to work that way. But
>I think it would be nice to be able to do it without creating temporary variable.
>
>here is the full code. I'm using php 4.2.2 and I'm running the code from comand line.
>(if I execute it from the web it gives something like 'document contains no data' instead
>of segmentation fault)
>
__________________________________________________________________
The NEW Netscape 7.0 browser is now available. Upgrade now! http://channels.netscape.com/ns/browsers/download.jsp
Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/