php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #79466 Fatal errors because of recursion should be exceptions
Submitted: 2020-04-10 16:24 UTC Modified: 2020-06-18 20:08 UTC
Votes:2
Avg. Score:3.5 ± 1.5
Reproduced:1 of 2 (50.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: david at grudl dot com Assigned:
Status: Open Package: Arrays related
PHP Version: Next Major Version OS:
Private report: No CVE-ID: None
 [2020-04-10 16:24 UTC] 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)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-04-10 17:07 UTC] requinix@php.net
-Summary: david@grudl.com +Summary: Fatal errors because of recursion should be exceptions -Package: Output Control +Package: Arrays related
 [2020-04-10 17:07 UTC] 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 17:10 UTC] 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 21:13 UTC] 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-15 10:31 UTC] 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-06-18 18:27 UTC] alexinbeijing at gmail dot com
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.
 [2020-06-18 20:08 UTC] nikic@php.net
@alexinbeijing: Non-identity comparisons already need to assume exceptions may be thrown due to overloaded comparison operators on objects. Identity comparisons may be assumed to be non-throwing currently, though there should not be that many of those.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC