Edit report at https://bugs.php.net/bug.php?id=55416&edit=1
ID: 55416
Comment by: danack@php.net
Reported by: roan dot kattouw at gmail dot com
Summary: array_map() throws PHP warning if the callback
throws an exception
Status: Closed
Type: Bug
Package: Arrays related
Operating System: Ubuntu Natty
PHP Version: 5.4.0alpha3
Assigned To: levim
Block user comment: N
Private report: N
New Comment:
The same odd behaviour is in SQLite3 where the code below gives the output:
PHP Warning: SQLite3::querySingle(): Unable to execute statement: in /test/src/exceptionTest1.php
on line 11
Exception: test exception
<?php
function my_udf_md5($string) {
throw new \Exception("test exception\n");
}
$db = new SQLite3('mysqlitedb.db');
$db->createFunction('my_udf_md5', 'my_udf_md5');
try {
$result = $db->querySingle('SELECT my_udf_md5("test")');
var_dump($result);
}
catch(\Exception $e) {
echo "Exception: ".$e->getMessage();
}
Previous Comments:
------------------------------------------------------------------------
[2015-01-06 00:31:51] levim@php.net
Automatic comment on behalf of levim
Revision: http://git.php.net/?p=php-src.git;a=commit;h=bb7ceb046eb5f0d5fa25066a3d7f9b4eb8cc3c93
Log: Fix bug #55416
------------------------------------------------------------------------
[2015-01-06 00:29:05] levim@php.net
Note that this same issue happens for array_reduce and array_filter, but not array_walk.
------------------------------------------------------------------------
[2014-10-30 20:50:29] tomasz at kowalczyk dot cc
Unfortunately I have the same problem on PHP 5.5.16 from Ondrej's PPA (Ubuntu 14.04). This is
an inconsistent behavior as other functions like array_walk() or array_reduce() don't do that.
------------------------------------------------------------------------
[2012-02-12 16:15:43] harvey dot robin at gmail dot com
I've just come across this too and I'm really surprised at this inconsistent behavior, for
me the question isn't "what kind of situation needs throw a exception in map
function" but "why would the map function behave differently to any other situation".
If you change array_map to array_walk in the original example then the exception propagates upward,
as expected.
At the very least, I'd expect to see a note on the PHP manual page warning users that
exceptions work differently for the callback parameter to array_walk.
------------------------------------------------------------------------
[2011-08-16 16:20:17] mah at everybody dot org
http://www.mediawiki.org/wiki/Special:Code/MediaWiki/94433
has Roan's actual use case.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=55416
--
Edit this bug report at https://bugs.php.net/bug.php?id=55416&edit=1