From: Operating system: N/A PHP version: Irrelevant Package: Unknown/Other Function Bug Type: Feature/Change Request Bug description:Non-object method call errors should be catchable with set_error_handler()
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 bug report at http://bugs.php.net/bug.php?id=51848&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=51848&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=51848&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=51848&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=51848&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=51848&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=51848&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=51848&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=51848&r=needscript Try newer version: http://bugs.php.net/fix.php?id=51848&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=51848&r=support Expected behavior: http://bugs.php.net/fix.php?id=51848&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=51848&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=51848&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=51848&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=51848&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=51848&r=dst IIS Stability: http://bugs.php.net/fix.php?id=51848&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=51848&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=51848&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=51848&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=51848&r=mysqlcfg