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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Fri May 09 21:01:27 2025 UTC