Re: __get() accessor question (a bug maybe?)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



TemuriI wrote:
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();

Ok, what you're seeing is related to the order in which PHP tries to find matching symbols. In checkID() it will not use __get() because it can access the member variable directly. When display() does it the fact that $_id is private trips it up so it falls back to trying __get(). The __get() is triggered everywhere as long as a better match cannot be found.

If you really need to have both go through __get(), name the internal private vars differently and have __get() translate the external name to the internal name.

-Stut

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux