Bug #54195 [Nab->Csd]: The notorious "Call to a member function .. on a non-object" fatal error
| From: | thekid@php.net | Date: | Wed, 08 Oct 2014 06:48:14 +0000 |
| Subject: | Bug #54195 [Nab->Csd]: The notorious "Call to a member function .. on a non-object" fatal error | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-187949@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=54195&edit=1
ID: 54195
Updated by: thekid@php.net
Reported by: landeholm at gmail dot com
Summary: The notorious "Call to a member function .. on a
non-object" fatal error
-Status: Not a bug
+Status: Closed
Type: Bug
Package: Scripting Engine problem
Operating System: Irrelevant
PHP Version: 5.3.5
-Assigned To:
+Assigned To: thekid
Block user comment: N
Private report: N
New Comment:
The fix for this bug has been committed.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
For Windows:
http://windows.php.net/snapshots/
Thank you for the report, and for helping us make PHP better.
https://wiki.php.net/rfc/catchable-call-to-member-of-non-object
Now in PHP 7
Previous Comments:
------------------------------------------------------------------------
[2011-03-09 17:14:57] landeholm at gmail dot com
NVM. These errors are catchable by the shutdown function. I tested in a context with errors
suppression enabled.
------------------------------------------------------------------------
[2011-03-09 17:05:18] tyra3l at gmail dot com
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
------------------------------------------------------------------------
[2011-03-08 15:40:17] 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 ...
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=54195&edit=1