|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65867 Countable interface infinite recursion.
Submitted: 2013-10-09 04:44 UTC Modified: 2013-10-09 13:14 UTC
From: kakserpompoyaitsam at gmail dot com Assigned:
Status: Wont fix Package: SPL related
PHP Version: 5.5.4 OS: Irrelevant
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.
Block user comment
Status: Assign to:
Bug Type:
From: kakserpompoyaitsam at gmail dot com
New email:
PHP Version: OS:


 [2013-10-09 04:44 UTC] kakserpompoyaitsam at gmail dot com
Easy reproducible segmentation fault.
It seems that count($this) doesn't check recursion. I think that count($this) should check if it is called inside of $this->count(), and if so, should ignore the Countable interface and just count the properties. Use case: if your object got special properties that you do not want to count, you can use something liek that: "function count() {return count($this) - numberOfSpecialProperties;}" 

Test script:
class A implements Countable {function count() {return count($this);}} count(new A);

Expected result:

Actual result:
Segmentation fault.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-10-09 04:46 UTC] kakserpompoyaitsam at gmail dot com
-Summary: strace php -r 'class A implements Countable {function count() {return count($th +Summary: Countable interface infinite recursion.
 [2013-10-09 04:46 UTC] kakserpompoyaitsam at gmail dot com
Changed title.
 [2013-10-09 13:14 UTC]
-Status: Open +Status: Wont fix
 [2013-10-09 13:14 UTC]
You can get the count via count((array)$this) or reflection, we won't add a special rule to count itself. We try to minimize bad effects of recursion where we can in a good way.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sun Dec 03 12:01:27 2023 UTC