Bug #17697: Object in object (object->reference object)
| From: | netadmin at isp dot pl | Date: | Tue, 11 Jun 2002 13:03:12 +0000 |
| Subject: | Bug #17697: Object in object (object->reference object) | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-10102@lists.php.net to get a copy of this message | ||
From: netadmin@isp.pl
Operating system: Red Hat 7.1
PHP version: 4.2.1
PHP Bug Type: Class/Object related
Bug description: Object in object (object->reference object)
<?
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.
--
Edit bug report at http://bugs.php.net/?id=17697&edit=1
--
Fixed in CVS: http://bugs.php.net/fix.php?id=17697&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=17697&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=17697&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=17697&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=17697&r=support
Expected behavior: http://bugs.php.net/fix.php?id=17697&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=17697&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=17697&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=17697&r=globals