php.net |  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
Votes:1
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 (profile)
Status: Closed Package: Documentation problem
PHP Version: master-Git-2012-10-31 (Git) OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: n at p12a dot org dot uk
New email:
PHP Version: OS:

 

 [2012-10-31 19:37 UTC] n at p12a dot org dot uk
Description:
------------
---
From manual page: http://www.php.net/function.count#refsect1-function.count-
parameters
---

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
3


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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)"
http://edit.php.net/?patchID=761&project=PHP
 [2012-11-12 22:33 UTC] salathe@php.net
Automatic comment from SVN on behalf of salathe
Revision: http://svn.php.net/viewvc/?view=revision&revision=328332
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 (mail+php@requinix.net)
 [2012-11-12 22:42 UTC] salathe@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: salathe
 [2012-11-12 22:42 UTC] salathe@php.net
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-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 16:01:29 2024 UTC