Reputation: 39208
If a variable is holding NULL
in PHP, attempting to access a property on it results in the notice "Trying to get property of non-object". If an attempt is made to call a method on it, however, the result is "Fatal error: Call to a member function method-name() on a non-object":
<?php
$obj = NULL;
var_dump($obj->prop);
$obj->method();
Is there a way to make PHP treat both of these runtime errors as Fatal Errors?
Upvotes: 1
Views: 511
Reputation: 1853
I don't have an idea but i think you can handle it manualy by catching the notice and throwing an exception followed by the line
exit();
;)
Upvotes: 1
Reputation: 522210
You can register your own error handler, which can promote this kind of error to a fatal error.
See http://php.net/set_error_handler and specifically the examples.
Upvotes: 1