Bug #68686 [Ver->Csd]: spurious warning about errors in array_*() callbacks
| From: | nikic@php.net | Date: | Wed, 06 Dec 2017 18:06:57 +0000 |
| Subject: | Bug #68686 [Ver->Csd]: spurious warning about errors in array_*() callbacks | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-212973@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: nikic@php.net
Reported by: clement dot herreman at gmail dot com
Summary: spurious warning about errors in array_*() callbacks
-Status: Verified
+Status: Closed
Type: Bug
Package: Arrays related
Operating System: OS X Maverick, Centos
PHP Version: 5.6.4
-Assigned To:
+Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
Closing as this is fixed in PHP 7 and 5.6 is out of active support.
Previous Comments:
------------------------------------------------------------------------
[2016-07-25 11:59:19] cmb@php.net
For the record: this issue has already been fixed as of PHP 7.0.0,
see <https://3v4l.org/kKKcT#v560> and <https://3v4l.org/sW6Mb>.
The fact that the error handler isn't called in the supplied test
script is expected behavior, because the exception has already
been caught.
------------------------------------------------------------------------
[2015-10-30 21:56:28] devsoc at gmail dot com
It seems that issue #55416 has not fixed this. The warning still occurs: PHP 5.6.4-4ubuntu6.3 (cli)
(built: Sep 29 2015 12:44:47).
array_reduce(['a'], function () { throw new \Exception(); });
------------------------------------------------------------------------
[2015-01-06 16:32:14] danack@php.net
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.
------------------------------------------------------------------------
[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