note 101778 deleted from language.oop5.magic by danbrown
| From: | danbrown@php.net | Date: | Tue, 11 Jan 2011 15:37:10 +0000 |
| Subject: | note 101778 deleted from language.oop5.magic by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-175634@lists.php.net to get a copy of this message | ||
Note Submitter: chris at sightworks dot com
----
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.