Is there a way I can tell PHP to throw an exception when I am trying to access a member or method on a null object?
E.g.:
$x = null;
$x->foo = 5; // Null field access
$x->bar(); // Null method call
Right now, I only get the following errors which are not nice to handle:
PHP Notice: Trying to get property of non-object in ...
PHP Warning: Creating default object from empty value in ...
PHP Fatal error: Call to undefined method stdClass::bar() in ...
I would like to have a specific exception being thrown instead. Is this possible?