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

From: Date: Tue, 06 Jan 2015 16:32:14 +0000
Subject: Bug #68686 [Opn]: set_error_handler cannot catch warning triggered by an exception in a callback
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-189688@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=68686&edit=1 ID: 68686 Updated by: danack@php.net Reported by: clement dot herreman at gmail dot com Summary: set_error_handler cannot catch warning triggered by an exception in a callback Status: Open Type: Bug Package: Output Control Operating System: OS X Maverick, Centos PHP Version: 5.6.4 Block user comment: N Private report: N New Comment: I'm not going to mark it as a duplicate, as they are really separate issues, but the issue described here should be resolved when the issue https://bugs.php.net/bug.php?id=55416 is fixed. Previous Comments: ------------------------------------------------------------------------ [2014-12-29 14:03:44] clement dot herreman at gmail dot com 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 this bug report at https://bugs.php.net/bug.php?id=68686&edit=1

« previous php.bugs (#189688) next »