Re: [RFC] Counting of non-countable objects

From: Date: Tue, 04 Oct 2016 10:17:36 +0000
Subject: Re: [RFC] Counting of non-countable objects
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-96213@lists.php.net to get a copy of this message
On 4 October 2016 at 10:32, Craig Duncan <php@duncanc.co.uk> wrote: > Hi everybody > > I'd like to propose the introduction of warning when counting objects that > can't be counted. > > The default behaviour is to return 1 for these objects, which can be > misleading and hide bugs when attempting to count iterable objects (eg > Generators). Adding a warning would alert developers to the issue > > https://wiki.php.net/rfc/counting_non_countables > > Thanks, > Craig I like this. I would personally like to see this behaviour deprecated and removed in 8.0 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.

« previous php.internals (#96213) next »