php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9479 new operator behaves in a really strange way
Submitted: 2001-02-27 09:16 UTC Modified: 2001-03-08 06:48 UTC
From: passionplay at hotmail dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0.4pl1 OS: Linux Mandrake
Private report: No CVE-ID: None
 [2001-02-27 09:16 UTC] passionplay at hotmail dot com
$objectlist=array();
class MyClass
{
  function MyClass()
  {
    global $objectlist;
    // Save the reference for later use
    $objectList[]=&$this;
  }
};

// the object referred to by $myobject is NOT in the array
$myobject = new MyClass();
// $myobject2 exists in the array
$myobject2 =& new MyClass();

It appears that there is an object being copied when returning from the constructor. What am I doing wrong?

I'm not supposed to return anything from the constuctor.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-03-08 06:48 UTC] stas@php.net
Yes, when you do a $obj = new Foo(), the object is copied.
Use =& if you want reference. 
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 05:01:30 2024 UTC