|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-03-08 15:40 UTC] landeholm at gmail dot com
Description:
------------
I had this problem a million times. It's very easy to accidentally invoke "Fatal Error: Call to a member function .. on a non-object". The problem is that this triggers an error so fatal that it can't even be caught by the shutdown function. This recently gave me a huge headache in a production system where an obscure bug where a variable contain null which was called on invoked a silent crash. It's a headache because I run everything in a framework with great wrappers for error handling/detection that are suppose to send me an email when obscure bugs get tripped. This obviously doesn't work when the PHP commits seppuku and explodes.
I don't see any reason for this error to be that fatal. Sure, keep the error fatal but at least allow the shutdown function to catch it.
Test script:
---------------
\register_shutdown_function(function(){
$e = \error_get_last();
if (!\is_null($e))
die('Houston we have a problem: ' . \print_r($e, true));
});
$hello = null;
$hello->bar();
Expected result:
----------------
Houston we have a problem: Array
(
...
Actual result:
--------------
Fatal error: Call to a member function bar() on a non-object in ...
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 01 16:00:02 2025 UTC |
I've mentioned this on the list, but to be archived: AFAIK register_shutdown_function should be called on every errors, even on the fatal ones, and it does. at least for me, both on windows, and linux: tyrael@devel-tyrael:~/c$ php -f fatal.php PHP Fatal error: Call to a member function bar() on a non-object in /home/tyrael/c/fatal.php on line 9 PHP Stack trace: PHP 1. {main}() /home/tyrael/c/fatal.php:0 Houston we have a problem: Array ( [type] => 1 [message] => Call to a member function bar() on a non-object [file] => /home/tyrael/c/fatal.php [line] => 9 ) as you can see from the output of the example code provided by Hannes Landeholm, it does called on the fatal error. if it doesn't work for Hannes, then I think that there are some difference in our setup/configuration. Tyrael