Re: echo count(false); == 1 ?!

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I accept your argument as logical but look at the documentation:

count() accepts 2 arguments. The first should be: "An array or countable
object". From here I can tell you that 90% of your cases do not comply with
the documentation so any argument pro or against us just speculation.
Comply with the documentation and then file bugs ;) null is neither an
array nor countable object. false also falls in that group! Use is_null for
null values or compare with true/false for bool. If you don't know the
possible range of your data the problem is not php ;)


On Wed, Nov 27, 2013 at 7:58 PM, Daevid Vincent <daevid@xxxxxxxxxx> wrote:

>
>
> > -----Original Message-----
> > From: Tsvetan Nikolov [mailto:live.webscore@xxxxxxxxx]
> > Sent: Wednesday, November 27, 2013 10:15 AM
> > To: Daevid Vincent
> > Cc: PHP-General
> > Subject: Re:  echo count(false); == 1 ?!
> >
> > Just think about it. When was the last time you counted something and the
> > result was false? It makes no sense. Logically counting should return
> > negative, 0 or positive value.
>
> Well in my case I have a method that populates a property. The property
> starts out as null (since it was never loaded). If there is an error, the
> method returns false, otherwise it fills the array.
>
> We could argue about flow/logic/etc. and how to "fix" my code.
>
> But logically, given how null/false/0 are usually treated, almost
> interchangeably, such as
>
> $foo = false;
> $foo = 0;
> $foo = null;
>
> If (!foo) ....
> All do the same thing
>
> It would stand to reason that count() would return 0 for anything that
> isn't
> an array, as there are ZERO elements in the "array".
>
>
>
>

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux