note 101778 added to language.oop5.magic

From: Date: Tue, 11 Jan 2011 06:54:28 +0000
Subject: note 101778 added to language.oop5.magic
Groups: php.notes 
Request: Send a blank email to php-notes+get-175619@lists.php.net to get a copy of this message
Re: Sammaye's comment: <?php class user_bo { public function __get($name) { /* snipped */ } public function __set($name, $value) { /* snipped */ } } ?> isset($object->someProperty) [and by extension, isset($object->$somePropertyName)] aren't working because the class does not have __isset($name) defined. If __isset() is not defined, it falls back on the original mechanism of PHP, which means it's looking for a property directly on the object - returning false every time, because it's not actually set *on the object*. If you're overloading __get and __set, you should also be overloading __isset and __unset - the full set of property manipulation functions. If not, you're going to get unexpected behavior as noted above, because PHP is using a combination of your overload and it's knowledge of the object's properties, which aren't the same. ---- Server IP: 69.147.83.197 Probable Submitter: 71.193.196.39 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.magic.php Edit -- https://master.php.net/note/edit/101778 Del: integrated -- https://master.php.net/note/delete/101778/integrated Del: useless -- https://master.php.net/note/delete/101778/useless Del: bad code -- https://master.php.net/note/delete/101778/bad+code Del: spam -- https://master.php.net/note/delete/101778/spam Del: non-english -- https://master.php.net/note/delete/101778/non-english Del: in docs -- https://master.php.net/note/delete/101778/in+docs Del: other reasons-- https://master.php.net/note/delete/101778 Reject -- https://master.php.net/note/reject/101778 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#175619) next »