|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #7511 References are not properly reassigned with classes
Submitted: 2000-10-28 08:13 UTC Modified: 2000-10-28 09:16 UTC
From: heathm at effinitylabs dot com Assigned:
Status: Closed Package: Class/Object related
PHP Version: 4.0.3 OS: RedHat Linux 7.0/6.2
Private report: No CVE-ID: None
 [2000-10-28 08:13 UTC] heathm at effinitylabs dot com
I found a rather strange problem with reference to objects.  Take the following:


class foo {
  var $Name;
  function foo($name) {
    $this->Name = $name;

$bar = new foo('Mike');
$list[] =& $bar;
$bar = new foo('Jeremy');
$list[] =& $bar;

while(list($key, $val) = each($list))
  echo "<br>$key = $val->Name";


When going through the loop and echoing the Name parameter the both return Jeremy.  If I unset $bar first (by uncommenting it) it works fine.  I'm not exactly sure what's going on but it is rather strange.



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2000-10-28 09:16 UTC]
no bug here, here?s what you did...

1) created instance of foo on uninitialized $bar
2) created a reference in array $list to $bar
(read the chapter "references explained in the manual" if
you don?t understand the following)
3) created instance of foo on $bar and it?s referenced array
4) created another reference in array $list to $bar

finally there are 3 structures beeing the same, $bar, array
element 1, array element 2
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Thu Nov 30 12:01:25 2023 UTC