Req #60577 [Asn->Csd]: count(new EmptyIterator) returns 1

From: Date: Sat, 29 Sep 2018 10:10:29 +0000
Subject: Req #60577 [Asn->Csd]: count(new EmptyIterator) returns 1
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-217276@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=60577&edit=1

 ID:                 60577
 Updated by:         nikic@php.net
 Reported by:        adam at sixohthree dot com
 Summary:            count(new EmptyIterator) returns 1
-Status:             Assigned
+Status:             Closed
 Type:               Feature/Change Request
 Package:            SPL related
 PHP Version:        5.4SVN-2011-12-20 (SVN)
 Assigned To:        levim
 Block user comment: N
 Private report:     N

 New Comment:

Yes, I believe the warning is sufficient. Using count() on iterators will generally not produce any
meaningful result, and the warning should make that obvious.


Previous Comments:
------------------------------------------------------------------------
[2018-08-10 03:15:29] carusogabriel@php.net

In PHP 7.2 we've introduced a warning for passing uncountable things to count: https://3v4l.org/WGmN2

May we close this one?

------------------------------------------------------------------------
[2014-05-09 14:13:52] levim@php.net

To be quite honest, this is the same exact 'bug'. The difference is really that some other
Iterators implement Countable so you would expect an EmptyIterator to be Countable and return its
count as 0.

The reason I haven't 'fixed' this bug yet is because there are fewer Iterators that
implement Countable than I initially thought. I'm not quite sure what to do and have been
working on other issues and features, notably adding return types: https://wiki.php.net/rfc/returntypehinting

------------------------------------------------------------------------
[2014-05-09 08:16:58] iam4webwork at hotmail dot com

If this is a bug, then why is #46322 not a bug?

------------------------------------------------------------------------
[2014-03-06 13:03:05] narf at devilix dot net

Technically not a duplicate, but very similar to #43650.

https://bugs.php.net/bug.php?id=43650

------------------------------------------------------------------------
[2013-09-12 20:33:14] levim@php.net

I confirmed this for versions 5.1.0 - 5.5.3.

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=60577


--
Edit this bug report at https://bugs.php.net/bug.php?id=60577&edit=1


Thread (8 messages)

« previous php.bugs (#217276) next »