#46322 [Opn]: count(FALSE) returns 1
| From: | dmitryshw at hotmail dot com | Date: | Thu, 16 Oct 2008 22:31:09 +0000 |
| Subject: | #46322 [Opn]: count(FALSE) returns 1 | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-129773@lists.php.net to get a copy of this message | ||
ID: 46322
User updated by: dmitryshw at hotmail dot com
Reported By: dmitryshw at hotmail dot com
Status: Open
Bug Type: Variables related
Operating System: Montavista
PHP Version: 5.2.6
New Comment:
Should have mentioned that I saw that this is mentioned as an "example"
but I don't see this being any less of a bug... unless you can please
explain how count(FALSE) makes sense to return 1.
Previous Comments:
------------------------------------------------------------------------
[2008-10-16 22:27:17] dmitryshw at hotmail dot com
Description:
------------
As title states, count for FALSE return 1. I came across the problem
when creating an array through unserialize and depending on count to
tell me how many elements the array has to know if I should use it. This
caused a bug when the string was empty, and unserialize faithfully
returned FALSE. However the result was used by the subsequent code as an
array because count returned 1. According to the docs, the parameter var
must have a Countable interface... so FALSE has a Countable interface??
Reproduce code:
---------------
$test = unserialize(NULL);
print count($test);
Expected result:
----------------
0
Actual result:
--------------
1
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=46322&edit=1