Hi all, here is the code I am having problem with:
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?!!
From what I see, the __get() accessor function is triggerred only from OUTSIDE the class.
Now, I realise that $_id is declared as private. But in order for get() or set() to fire up, member either should not be declared at all, or declared as private. In any case, shouldn't private members move over to extending class? They aren't accessible from outside, but should be readable by all methods of extending class (and, actually checkID() is a method of the base class).
Or am I wrong there?
I have PHP Version 5.1.6, installed on Win32 (unfortunately).
Thank you in advance,
Temuri