php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #33282 Reference is killed by unset but not by other =&
Submitted: 2005-06-09 15:33 UTC Modified: 2006-11-07 20:24 UTC
From: devik at cdi dot cz Assigned: dmitry (profile)
Status: Closed Package: Feature/Change Request
PHP Version: 5CVS-2005-06-13 OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: devik at cdi dot cz
New email:
PHP Version: OS:

 

 [2005-06-09 15:33 UTC] devik at cdi dot cz
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).

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-09-02 07:42 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip

And DO NOT invent your own style for the PHP version field!!
(Hint: PHP version string does NOT contain 'PHP' in it..)


 [2005-09-02 08:33 UTC] devik at cdi dot cz
Sorry but I still see the problem. Regarding version,
I used directory name as I found nothing like 5CVS-2005-06-13
in the downloaded package.
 [2006-11-07 20:24 UTC] iliaa@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 13:01:29 2024 UTC