php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35722 links troubles
Submitted: 2005-12-18 04:43 UTC Modified: 2005-12-18 11:11 UTC
Votes:1
Avg. Score:2.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: zerkms at mail dot ru Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.1.1 OS: independent
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: zerkms at mail dot ru
New email:
PHP Version: OS:

 

 [2005-12-18 04:43 UTC] zerkms at mail dot ru
Description:
------------
something strange with links to array and objects

Reproduce code:
---------------
//1st
$a = array('a' => 'zzzz');
$q =& $a['a'];
echo $q;
$a = array('a' => 'qwe');
echo $q;


//2nd
$a = new stdclass();
$a->s = 333;
$q =& $a;
echo $q->s;
$a = new stdclass();
$a->s = 444;
echo $q->s; 

Expected result:
----------------
//1st
zzzzqwe

//2nd
333333

Actual result:
--------------
//1st
zzzzzzzz

//2nd
333444

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-12-18 11:11 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

There is nothing wrong here. In the first example you overwrite the whole array with $a = array(\'a\' => \'qwe\'); and you\'re not just updating the first element. This breaks the refererence (and it should do that).

In the second example you overwrite $a with $a = new stdclass();, but as you assigned $q to $a by reference, $a and $q are simply the same variable here. Hence modifying $a->s to 444 changes the s property for $q too.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Dec 04 03:00:01 2025 UTC