#26441 [Asn->Csd]: Strange behavior when __set() return a member variable

From: Date: Fri, 09 Apr 2004 14:43:30 +0000
Subject: #26441 [Asn->Csd]: Strange behavior when __set() return a member variable
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-57861@lists.php.net to get a copy of this message
ID: 26441 Updated by: andi@php.net Reported By: chernyshevsky at hotmail dot com -Status: Assigned +Status: Closed Bug Type: Zend Engine 2 problem Operating System: * PHP Version: 5CVS-2004-03-30 Assigned To: andi New Comment: This bug has been fixed in CVS. Snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. Thank you for the report, and for helping us make PHP better. Previous Comments: ------------------------------------------------------------------------ [2004-04-07 11:19:09] sniper@php.net Andi, you decide if this is docu prob or real bug.. :) ------------------------------------------------------------------------ [2004-04-01 01:02:14] amt@php.net Okay, but it still shouldn't act screwy when you do return that value. It should just ignore the return value of __set(). ------------------------------------------------------------------------ [2004-03-31 23:12:24] chernyshevsky at hotmail dot com I think it was marked bogus because you don't actually need to return from __set(). The engine will call __get() when you have something like $a = $object->prop = "Hello". ------------------------------------------------------------------------ [2003-11-28 01:13:50] chernyshevsky at hotmail dot com Description: ------------ When __set() returns an element of a member array, it seems to corrupt the array. Works as expected when "return" is removed. Reproduce code: --------------- class Test { var $values; function __construct() { $this->values = array(); } function __set($name, $value) { return $this->values[$name] = $value; } function __get($name) { return $this->values[$name]; } }; $a = new Test(); $a->greeting = "Hello"; echo $a->greeting; Expected result: ---------------- Hello Actual result: -------------- 1 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=26441&edit=1

« previous php.bugs (#57861) next »