php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: kakserpompoyaitsam at gmail dot com
New email:
PHP Version: OS:

 

 [2013-10-09 04:44 UTC] kakserpompoyaitsam at gmail dot com
Description:
------------
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:
----------------
0

Actual result:
--------------
Segmentation fault.

Patches

Pull Requests

History

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] johannes@php.net
-Status: Open +Status: Wont fix
 [2013-10-09 13:14 UTC] johannes@php.net
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-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 13:01:31 2024 UTC