php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70113 IteratorIterator doesn't delegate count through count() array function
Submitted: 2015-07-22 12:45 UTC Modified: 2015-07-22 17:07 UTC
From: zoeslam at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: SPL related
PHP Version: 5.6.11 OS: Linux
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: zoeslam at gmail dot com
New email:
PHP Version: OS:

 

 [2015-07-22 12:45 UTC] zoeslam at gmail dot com
Description:
------------
FilterIterator doesn't delegate count through count() array function.
It's ok if called as a method.

It affects all PHP versions: http://3v4l.org/jKOgZ

Test script:
---------------
<?php

class MyFilter extends FilterIterator
{
    public function accept()
    {
        return true;
    }
}

$it = new ArrayIterator(array(1, 2, 3));
$fi = new MyFilter($it);

var_dump($it->count());
var_dump($fi->count());

var_dump(count($it));
var_dump(count($fi));


Expected result:
----------------
int(3)
int(3)
int(3)
int(3)


Actual result:
--------------
int(3)
int(3)
int(3)
int(1)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-07-22 12:48 UTC] zoeslam at gmail dot com
-Summary: FilterIterator doesn't delegate count through count() array function +Summary: IteratorIterator doesn't delegate count through count() array function
 [2015-07-22 12:48 UTC] zoeslam at gmail dot com
The bug is in the main IteratorIterator class I suppose: http://3v4l.org/e14aG
 [2015-07-22 17:07 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2015-07-22 17:07 UTC] cmb@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

FilterIterator doesn't implement Countable. You can do it
yourself, though, see <http://3v4l.org/gfZrT>.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 28 23:01:32 2024 UTC