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 Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or 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

Add a Patch

Pull Requests

Add a Pull Request

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: Tue Apr 23 22:01:31 2024 UTC