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
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: 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: Sat Dec 21 15:01:29 2024 UTC