Bug #68686 [NEW]: set_error_handler cannot catch warning triggered by an exception in a callback

From: Date: Mon, 29 Dec 2014 14:03:45 +0000
Subject: Bug #68686 [NEW]: set_error_handler cannot catch warning triggered by an exception in a callback
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-189310@lists.php.net to get a copy of this message
From: clement dot herreman at gmail dot com Operating system: OS X Maverick, Centos PHP version: 5.6.4 Package: Output Control Bug Type: Bug Bug description:set_error_handler cannot catch warning triggered by an exception in a callback Description: ------------ When throwing an exception is the callback of array_map or array_filter, an E_WARNING is triggered ("Warning: array_filter(): An error occurred while invoking the filter callback in /your/script.php on line XX"). If no error handler is set, then the warning is directly sent to the output. If an error handler is set via set_error_handler then: * The error handler is not called at all * The warning simply disappear and are nowhere to be found Test script: --------------- <?php /* Sample script: php this.php to see the warning in the output * php this.php 1 to try to setup an error handler */ if (!empty($argv[1])) { set_error_handler(function ($errno, $errstr) { printf("(%d) %s\n", $errno, $errstr); }); } function failFilter() { try { array_filter([1, 2, 3, 4], function ($n) { throw new \Exception('Some exception'); }); } catch (\Exception $e) { } } function failMapException() { try { array_map(function ($n) { throw new \Exception('oops'); }, [1, 2, 3]); } catch (\Exception $e) { } } function failMapTriggerError() { try { array_map(function ($n) { trigger_error('Some error'); }, [1, 2, 3]); } catch (\Exception $e) { } } failFilter(); failMapException(); failMapTriggerError(); Expected result: ---------------- (1024) Some exception (1024) Some exception (1024) Some exception (1024) oops (1024) oops (1024) oops (1024) Some error (1024) Some error (1024) Some error Actual result: -------------- cherreman@mlil-cherreman ~ $ php test.php PHP Warning: array_filter(): An error occurred while invoking the filter callback in /Users/cherreman/test.php on line 14 Warning: array_filter(): An error occurred while invoking the filter callback in /Users/cherreman/test.php on line 14 PHP Warning: array_map(): An error occurred while invoking the map callback in /Users/cherreman/test.php on line 25 Warning: array_map(): An error occurred while invoking the map callback in /Users/cherreman/test.php on line 25 PHP Notice: Some error in /Users/cherreman/test.php on line 35 Notice: Some error in /Users/cherreman/test.php on line 35 PHP Notice: Some error in /Users/cherreman/test.php on line 35 Notice: Some error in /Users/cherreman/test.php on line 35 PHP Notice: Some error in /Users/cherreman/test.php on line 35 Notice: Some error in /Users/cherreman/test.php on line 35 cherreman@mlil-cherreman ~ $ php test.php 1 (1024) Some error (1024) Some error (1024) Some error -- Edit bug report at https://bugs.php.net/bug.php?id=68686&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=68686&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=68686&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=68686&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=68686&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=68686&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=68686&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=68686&r=needscript Try newer version: https://bugs.php.net/fix.php?id=68686&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=68686&r=support Expected behavior: https://bugs.php.net/fix.php?id=68686&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=68686&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=68686&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=68686&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68686&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=68686&r=dst IIS Stability: https://bugs.php.net/fix.php?id=68686&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=68686&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=68686&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=68686&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=68686&r=mysqlcfg

« previous php.bugs (#189310) next »