There's an open book quiz for a job application I'm doing, and it's obviously highlighted a shortcoming in my php knowledge.
Note, I'm not asking for the answer directly, I'm asking to be shown what I'm misunderstanding/lacking in how to answer it. The question is:
3. Finish the following class to print "Person->name has been zapped" when the
following is executed on a Person object: print $person;
class Person{
private $name = '';
public function __construct($name){
$this->name = $name;
}
}
$person = new Person('fred');
print $person; // fred has been zapped
Now, either there's some way of adding exception handling to the class (though I would have thought 'print' would be the thing throwing the exception, or I'm just misunderstanding the question. I do know (from a quick test) that putting the print in a try..catch still causes the program to fail with a "catchable fatal error" (my catch did not fire).
What should I be reading up on ?
David