php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9620 new operator does not behave correctly
Submitted: 2001-03-08 08:27 UTC Modified: 2001-03-09 22:01 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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
47 + 28 = ?
Subscribe to this entry?

 
 [2001-03-08 08:27 UTC] passionplay at hotmail dot com
I submitted this bug previous and was told that this is how the new operator is supposed to work. I submit to you that in every other instance this makes sense, but for self referencing constructs, especially with the new operator, the fact that =new is not interpreted as =&new does not make sense whatsoever because why would I want to assign a copy of the object I just created, especially if that object opens files? Is there EVER a situation where I want to assign ANYTHING other than the object I just created???

Thank you.

--------- Response follows ------------------

Yes, when you do a $obj = new Foo(), the object is copied.
Use =& if you want reference.

Previous Comments:
---------------------------------------------------------------------------

[2001-02-27 09:16:56] passionplay@hotmail.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 08:50 UTC] stas@php.net
Same as #9479. If you want further discussion on it, reopen it.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 30 16:01:29 2024 UTC