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

From: Date: Wed, 07 Apr 2004 15:19:09 +0000
Subject: #26441 [Opn->Asn]: Strange behavior when __set() return a member variable
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-57721@lists.php.net to get a copy of this message
ID: 26441 Updated by: sniper@php.net Reported By: chernyshevsky at hotmail dot com -Status: Open +Status: Assigned Bug Type: Zend Engine 2 problem Operating System: * PHP Version: 5CVS-2004-03-30 -Assigned To: +Assigned To: andi New Comment: Andi, you decide if this is docu prob or real bug.. :) Previous Comments: ------------------------------------------------------------------------ [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 (#57721) next »