Re: [RFC] Counting of non-countable objects
| From: | Craig Duncan | Date: | Tue, 04 Oct 2016 10:29:58 +0000 |
| Subject: | Re: [RFC] Counting of non-countable objects | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-96214@lists.php.net to get a copy of this message | ||
On 4 October 2016 at 11:17, Leigh <leight@gmail.com> wrote:
> You specifically mention that counting scalars is unaffected, is there
> a legitimate use-case for being able to use count() on them?
>
> I'd say using count() on a string or an int also constitutes a hidden
> bug, as it also always returns 1 regardless of the value.
>
I agree, and I'm happy to include scalars in the RFC if that's desired by
the majority.
Calling count() on a scalar is likely to cause a warning at some point, so
it's not as "hidden" as the iterator example:
if (count($string) > 0) {
foreach ($string as $value) {