php.net |  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
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: heathm at effinitylabs dot com
New email:
PHP Version: OS:

 

 [2000-10-28 08:13 UTC] heathm at effinitylabs dot com
I found a rather strange problem with reference to objects.  Take the following:

<?php

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

$bar = new foo('Mike');
$list[] =& $bar;
//unset($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.

Mike


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-10-28 09:16 UTC] waldschrott@php.net
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
element
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-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 01:01:30 2024 UTC