class baseForm { private $_id = 10; function __get($member) { echo "Accessing member \"{$member}\" : <br />\n"; return $this->$member; } function checkID() { echo $this->_id."<br />\n"; } } class inputText extends baseForm { function display() { $this->checkID(); echo $this->_id."<br />\n"; } } $f = new inputText(); echo $f -> display();
The question is: why the string 'Accessing member "_id" :' is only displayed once? If you look at the code - it actually accesses $_id member TWICE. But __get() gets gets triggered only once. WHY?!!
The call to $this->_id in the baseForm class doesn't call __get. The __get method isn't called when the baseForm checkID() method is called because it is a method within the baseForm class, thus it has access to the private instance variable $_id and doesn't use the magic method. If you dont define the variable in the class definition (but say, set it in the constructor) the 'Accessing member' text will appear twice. -- Marc Gear marcgear@xxxxxxxxx -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php