On Tue, Oct 4, 2016 at 12:29 PM, Craig Duncan <p...@duncanc.co.uk> wrote:
> On 4 October 2016 at 11:17, Leigh <lei...@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) { > A confounding factor is that count() has an alias sizeof() and for people coming from a C-like background it is quite natural to try to apply sizeof() to a string in order to get its length. This will silently "work", but return a meaningless result. So, definitely +1 on a warning for all non-array non-Countable cases. Nikita