Req #79466 [Com]: Fatal errors because of recursion should be exceptions
Edit report at https://bugs.php.net/bug.php?id=79466&edit=1
ID: 79466
Comment by: alexinbeijing at gmail dot com
Reported by: david at grudl dot com
Summary: Fatal errors because of recursion should be
exceptions
Status: Open
Type: Feature/Change Request
Package: Arrays related
PHP Version: Next Major Version
Block user comment: N
Private report: N
New Comment:
It's nice to see that PHP already has a mechanism built in to detect a recursive traversal of
an array.
The interpreter fails with "nesting level too deep" when a recursive traversal is detected
at zend_hash.c:2652. My concern is that if that line is changed to throw an exception, a lot of
things may be affected -- there are a huge number of places in the codebase which (directly or
indirectly) use this code.
Previous Comments:
------------------------------------------------------------------------
[2020-04-15 10:31:14] nikic@php.net
I agree that it would be good to make this a catchable exception at least.
Even better would be to not throw at all and directly support comparison of cyclic structures, but
that's not easy (to do efficiently).
------------------------------------------------------------------------
[2020-04-10 21:13:18] david at grudl dot com
Sorry for email in summary and wrong package! I found out that LastPass did it, it won't happen
again :)
------------------------------------------------------------------------
[2020-04-10 17:10:12] bugreports at gmail dot com
may i suggest that you don#t always fill your email into "summary"?
[NEW]: david@grudl.com is not very helpful
------------------------------------------------------------------------
[2020-04-10 17:07:50] requinix@php.net
The recursion doesn't have to be fatal: personally, I would rather have the functions warn that
there was a recursive structure and then continue on.
------------------------------------------------------------------------
[2020-04-10 16:24:20] david at grudl dot com
Description:
------------
Operator === and a lot of native functions (such as in_array, array_search(), ...) can cause fatal
error. Example:
$foo = [];
$foo[] = [ &$foo ];
array_search($foo, $foo);
Problem is that this fatal error cannot be catched in try ... catch block. It would be nice if Error
was thrown instead.
(related to #62171)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79466&edit=1
Thread (7 messages)