Req #51848 [Opn->Csd]: Non-object method call errors should be catchable with set_error_handler()

From: Date: Tue, 07 Oct 2014 22:11:55 +0000
Subject: Req #51848 [Opn->Csd]: Non-object method call errors should be catchable with set_error_handler()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-187925@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=51848&edit=1 ID: 51848 Updated by: thekid@php.net Reported by: jelle at gmta dot nl Summary: Non-object method call errors should be catchable with set_error_handler() -Status: Open +Status: Closed Type: Feature/Change Request Package: Scripting Engine problem Operating System: N/A PHP Version: Irrelevant -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 Fixed in PHP 7. Previous Comments: ------------------------------------------------------------------------ [2010-05-18 10:10:51] jelle at gmta dot nl Description: ------------ 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: --------------- <?php function handleError($errno, $errstr, $errfile, $errline, $errcontext) { print_r(func_get_args()); exit(); } set_error_handler('handleError'); $a = NULL; $a->nonExistingMethod(); 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=51848&edit=1

« previous php.bugs (#187925) next »