#29175 [Bgs]: __get and __set are not called when property explicitly defined public or var

From: Date: Thu, 15 Jul 2004 12:33:52 +0000
Subject: #29175 [Bgs]: __get and __set are not called when property explicitly defined public or var
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-62375@lists.php.net to get a copy of this message
ID: 29175 User updated by: jbeall at heraldic dot us Reported By: jbeall at heraldic dot us Status: Bogus Bug Type: Zend Engine 2 problem Operating System: Linux PHP Version: 5.0.0 New Comment: Interesting. The documentation suggests otherwise, both here: http://us2.php.net/manual/en/migration5.oop.php#migration5.oop.overload and here: http://us4.php.net/overload It would probably be a good idea to update the docs so they make it clear what the intended behavior is. Previous Comments: ------------------------------------------------------------------------ [2004-07-15 04:20:12] amt@php.net This is the intended behavior. __get() and __set() are only triggered when a property *does not* exist. ------------------------------------------------------------------------ [2004-07-15 03:56:29] jbeall at heraldic dot us Description: ------------ If you define a property as public, and then also define the __get() and __set() functions within the same class, those functions are not called. Reproduce code: --------------- class Sub { public $someProp; function __get($prop) { echo "Property $prop called\n"; } function __set($prop, $val) { echo "Property $prop set to $val\n"; } } $foo = new Sub(); $foo->someProp = 10; echo $foo->someProp; Expected result: ---------------- Property someProp set to 10 Property someProp called Actual result: -------------- 10 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=29175&edit=1

« previous php.bugs (#62375) next »