php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45145 reference aliasing is working backwards, wiping the var
Submitted: 2008-06-01 14:35 UTC Modified: 2008-06-02 14:07 UTC
From: phpbug at thoria dot org Assigned:
Status: Not a bug Package: Variables related
PHP Version: 5.2CVS-2008-06-01 (snap) OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: phpbug at thoria dot org
New email:
PHP Version: OS:

 

 [2008-06-01 14:35 UTC] phpbug at thoria dot org
Description:
------------
On versions 5.2.3 and 4.3.1(Zend off), on different shared hosting servers.

Within one large function/loop in my app

$x = &$y;

y is destroyed and replaced by x, intermittently. unset($x) is ignored if placed above it, and x still goes into y. There is no workaround, besides using $x = $y. I think any ref assignments in this loop behave like this if $x has had a prior value.

You will need to have my whole app installed. It's so weird, it makes me feel dumb to submit it.

Reproduce code:
---------------
$bb = "original string";
$aa = "moo";
unset($aa);
$aa = &$bb;
echo "AA->$aa, BB->$bb <br>";

or

$bb = "original string";
$aa = "moo";
$aa = &$bb;
echo "AA->$aa, BB->$bb <br>";

The following is OK

$aa = "moo";
$bb = "original string";
$aa = &$bb;
echo "AA->$aa, BB->$bb <br>";

Expected result:
----------------
AA->original string, BB->original string 
AA->original string, BB->original string 
AA->original string, BB->original string 

Actual result:
--------------
AA->original string, BB->original string 
AA->moo, BB->moo 
AA->moo, BB->moo 
AA->moo, BB->moo 
AA->moo, BB->moo 
AA->moo, BB->moo 
AA->original string, BB->original string 
AA->moo, BB->moo 
AA->moo, BB->moo 
AA->original string, BB->original string 
AA->moo, BB->moo 
AA->moo, BB->moo 
AA->moo, BB->moo 
AA->moo, BB->moo 
AA->moo, BB->moo 
AA->moo, BB->moo 
AA->moo, BB->moo 
AA->moo, BB->moo 
AA->moo, BB->moo 
AA->moo, BB->moo 
AA->moo, BB->moo 
AA->moo, BB->moo 
AA->moo, BB->moo 
AA->moo, BB->moo 
AA->moo, BB->moo 
AA->moo, BB->moo 
AA->moo, BB->moo 
AA->moo, BB->moo 
AA->moo, BB->moo 
AA->moo, BB->moo 
AA->moo, BB->moo 
AA->moo, BB->moo 
AA->moo, BB->moo 
AA->moo, BB->moo 
AA->moo, BB->moo 
AA->moo, BB->moo 
AA->moo, BB->moo 
AA->moo, BB->moo 
AA->moo, BB->moo 
AA->moo, BB->moo 
AA->moo, BB->moo 
AA->moo, BB->moo 
AA->moo, BB->moo 
AA->original string, BB->original string 
AA->moo, BB->

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-06-02 08:34 UTC] phpbug at thoria dot org
Now, I'm really scratching my head. After hacking my code down for hours, I realised it could be replicated in a few lines. Iteration 1 is OK. Iteration 2 produces the effect. The unset is not necessary. Iteration 3 shows how it goes away if $x='moo' is declared first.

<?php

echo "1<br>";

$y = "original string";
$x = "moo";
unset($x);
$x = &$y;
echo "X $x  Y $y<br><br>";

echo "2<br>";

$y = "original string";
$x = "moo";
unset($x);
$x = &$y;
echo "X $x  Y $y<br><br>";

echo "3<br>";

$x = "moo";
$y = "original string";
$x = &$y;
echo "X $x  Y $y<br><br>";

?>
 [2008-06-02 08:56 UTC] phpbug at thoria dot org
Arrrhhh. I'm just guilty of C-thinking.
 [2008-06-02 14:07 UTC] phpbug at thoria dot org
------------------------------------------------------------------
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri May 09 17:01:28 2025 UTC