Bug #11092 Updated: (Yet Another) References Weirdness

From: Date: Thu, 24 May 2001 17:18:58 +0000
Subject: Bug #11092 Updated: (Yet Another) References Weirdness
Groups: php.dev 
Request: Send a blank email to php-dev+get-56645@lists.php.net to get a copy of this message
ID: 11092 Updated by: sbergmann Reported By: sbergmann@php.net Status: Open Bug Type: Scripting Engine problem Operating system: PHP Version: 4.0.5 Assigned To: Comments: Just noticed: It works as expected when I replace $a = $b->add_a(); with $a =& $b->add_a(); But this is not the syntax I was thinking of for my class. The user, which probably doesn't know of the class's internals, now has always use the =& assignment operator. This is definetly error-prone. Previous Comments: --------------------------------------------------------------------------- [2001-05-24 13:04:25] sbergmann@php.net There seems to be a problem with objects returned from class methods by reference: <?php class a { var $data; function add_data($data) { $this->data[] = $data; } } class b { var $a; function &add_a() { $this->a = new a; return $this->a; } function dump() { print_r($this->a->data); } } $b = new b; $a = $b->add_a(); $a->add_data('test'); // works not $b->a->add_data('test'); // works $b->dump(); ?> --------------------------------------------------------------------------- ATTENTION! Do NOT reply to this email! To reply, use the web interface found at http://bugs.php.net/?id=11092&edit=2

« previous php.dev (#56645) next »