|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #51848 Non-object method call errors should be catchable with set_error_handler()
Submitted: 2010-05-18 10:10 UTC Modified: 2014-10-07 22:11 UTC
Avg. Score:5.0 ± 0.0
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:1 (33.3%)
From: jelle at gmta dot nl Assigned: thekid
Status: Closed Package: Scripting Engine problem
PHP Version: Irrelevant OS: N/A
Private report: No CVE-ID:
 [2010-05-18 10:10 UTC] jelle at gmta dot nl
Calling member functions on non-object variables fails with a fatal error. This error is not catchable using PHP's internal error handling configured using set_error_handler(). See the test script below for an example.

I think error handlers should be able to catch this problem. We use a lot of ORM in our applications which involves a lot of object getting, and sometimes we forget to check whether we really have an object. We rely on PHP's error handling to tell us exactly what's going on but cannot use this functionality at this moment.

I believe some errors are not handled by the custom handler because of the unknown or unstable state the engine resides in after the the error. For this case, it's true as the desired method execution / code jump never takes place. I think this can be solved (for this particular error) by stopping execution after calling the custom handler.

Bug #12136 (closed) describes this problem but describes it as a design feature. I think this design can be improved a bit.

Test script:

function handleError($errno, $errstr, $errfile, $errline, $errcontext) {


$a = NULL;

Expected result:
The custom error handler function arguments as per print_r(func_get_args()).

Actual result:
Fatal error: Call to a member function nonExistingMethod() on a non-object in fatalErrorHandling.php on line 11


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-01 15:36 UTC]
-Package: Unknown/Other Function +Package: Scripting Engine problem
 [2014-10-07 22:11 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: thekid
 [2014-10-07 22:11 UTC]
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

 For Windows:
Thank you for the report, and for helping us make PHP better.

Fixed in PHP 7.
PHP Copyright © 2001-2015 The PHP Group
All rights reserved.
Last updated: Mon Oct 05 04:01:32 2015 UTC