I'm reading this ebook, Beginning PHP5 and Mysql: From Novice to Professional, and in the OOP section, I'm trying out this sample code to reproduce the same results on my computer vs the book.
class Staff
{
var $name;
var $city;
protected $wage;
function __get($propName)
{
echo "__get called!<br />";
$vars = array("name","city");
if (in_array($propName, $vars))
{
return $this->$propName;
} else {
return "No such variable!";
}
}
}
$employee = new Staff();
$employee->name = "Mario";
echo $employee->name."<br />";
echo $employee->age;
In the book - the results are shown as:
Mario
__get called!
No such variable!
But on my computer:
Mario
Only the first line. The other two lines were "ignored". Why is that?!?!
Is there some configuration setting on my php.ini that I need to modify to get this working? Can someone please help to explain?