Throwing error when calling a member function on a null var
Posted: Tue Jan 09, 2007 12:35 am
I've been having problems lately with calling member functions on variables whose values may not have changed from null yet due to other bugs. I'm running PHP 5.1.2 and this is really problematic because it doesn't throw any error, it just stops execution and prints a blank page.
Three closely related problems do in fact throw errors:
The above will throw a notice: "Trying to get property of non-object". Or,
The above will throw a notice: "Undefined variable: foo". Or,
The above will also throw the same notice: "Undefined variable: foo".
However, this piece of code
will throw no error and just make the screen blank. I'd really like to be able to catch this type of error, but extensive searching in the usual places (google, PHP documentation and forums) has turned up nothing. Can anyone help?
Three closely related problems do in fact throw errors:
Code: Select all
$foo = null;
echo $foo->field;Code: Select all
echo $foo->field;Code: Select all
echo $foo->method()However, this piece of code
Code: Select all
$foo = null;
echo $foo->method();