#33282 [NEW]: Reference is killed by unset but not by other =&
From: devik at cdi dot cz
Operating system: Linux
PHP version: 5.0.4
PHP Bug Type: Scripting Engine problem
Bug description: Reference is killed by unset but not by other =&
Description:
------------
This is variation on #15025. But I accept the bug is feature and I show
other bug it triggers.
Basic problem is that when you take ref of array item then the item will
turn into reference (which will survive even array copy). I don't see it
as too big problem as long as I can get rid of the reference.
"unset" does the trick as expected:
$r =& $A[0];
unset($r); - $A[0] is not reference any more
But something like:
$r =& $othervar;
doesn't kill reference - you see zval with is_ref=1 and refcount=1.
It prevents you from writing handy code:
$c = &$c[$i] when traversing complex structures.
Reproduce code:
---------------
<?
$a = array(1,2);
$b =& $a[0];
echo "Now a[0] is reference, no problem\n";
debug_zval_dump($a);
$b =& $a[1];
echo "Now a[0] has no reason to be reference any longer, but a[1] is\n";
debug_zval_dump($a);
unset($b);
echo "Now a[1] reference is gone too BUT WAIT, a[0] is still a ref !\n";
debug_zval_dump($a);
?>
Expected result:
----------------
I expect $a without references.
Actual result:
--------------
$a[0] is reference with refcount(1).
--
Edit bug report at http://bugs.php.net/?id=33282&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=33282&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=33282&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=33282&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=33282&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=33282&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=33282&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=33282&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=33282&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=33282&r=support
Expected behavior: http://bugs.php.net/fix.php?id=33282&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=33282&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=33282&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=33282&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=33282&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=33282&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=33282&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=33282&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=33282&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=33282&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=33282&r=mysqlcfg
Thread (7 messages)
- devik at cdi dot cz