|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #63406 Count *does* detect infinite recursion
Submitted: 2012-10-31 19:37 UTC Modified: 2012-11-12 22:42 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: n at p12a dot org dot uk Assigned: salathe
Status: Closed Package: Documentation problem
PHP Version: master-Git-2012-10-31 (Git) OS:
Private report: No CVE-ID:
 [2012-10-31 19:37 UTC] n at p12a dot org dot uk
From manual page:

The manual says "count() does not detect infinite recursion". But count() does.

Test script:
$a = array();
$a[] = &$a;
echo count($a, 1), "\n"

Expected result:
Most probably an out-of-memory error, which is what I get when infinitely 
recursing in a user-defined function.

Actual result:
PHP Warning:  count(): recursion detected in Command line code on line 1


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-11-03 01:07 UTC] mail+php at requinix dot net
...and the number may be wildly inaccurate. Sounds like a bug: counts first and 
stops recursion second?

$a = array(1, 2, 3);
$a[] =& $a;
$a[] =& $a;
$a[] =& $a;
echo count($a, COUNT_RECURSIVE); // 78

Did you know you can easily submit changes to the online documentation? Look for 
the [edit] in the top-right corner of manual pages.

I've submitted some changes for you:
"count: detects recursion (bug #63406)"
 [2012-11-12 22:33 UTC]
Automatic comment from SVN on behalf of salathe
Log: count() does in fact discover recursion and issues an E_WARNING in response... but it will probably return a much higher number than it should. (doc #63406)

Provided by anonymous #22227 (
 [2012-11-12 22:42 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: salathe
 [2012-11-12 22:42 UTC]
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

Committed requinix's patch.
PHP Copyright © 2001-2015 The PHP Group
All rights reserved.
Last updated: Thu Nov 26 03:01:32 2015 UTC