php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #17697 Object in object (object->reference object)
Submitted: 2002-06-11 09:03 UTC Modified: 2002-06-11 09:25 UTC
From: netadmin at isp dot pl Assigned:
Status: Closed Package: Class/Object related
PHP Version: 4.2.1 OS: Red Hat 7.1
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: netadmin at isp dot pl
New email:
PHP Version: OS:

 

 [2002-06-11 09:03 UTC] netadmin at isp dot pl
<?
class A
{
    var $var_a;

    function A()
    {
        $this->set_a("old");
    }

    function set_a($a) { $this->var_a=$a; }
}

class B
{
    var $obj_a;

    function B()
    {
        $this->obj_a=new A;
    }
}

$my=new B;
var_dump($my);

$my->obj_a->set_a("new");
var_dump($my);

?>

I create new object from class B ($my)

variable $obj_a in object $my IS OBJECT from class A.

var_dump($my) return 

object(b)(1) { ["obj_a"]=> object(a)(1) { ["var_a"]=> string(3) "old" } } 

It's ok.

After that I call a method from class A

$my->obj_a->set_a("new");

This method change variable $var_a, but after that variable $obj_a IS REFERENCE to object A

var_dump($my) return :

object(b)(1) { ["obj_a"]=> &object(a)(1) { ["var_a"]=> string(3) "new" } } 

$obj_a was object, but now $obj_a is reference to object.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-11 09:25 UTC] mfischer@php.net
This is fixed in the Zend Engine 2, see php.net for the preview announcement.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 11 20:01:31 2024 UTC