ID: 46322 User updated by: dmitryshw at hotmail dot com Reported By: dmitryshw at hotmail dot com Status: Bogus Bug Type: Variables related Operating System: Montavista PHP Version: 5.2.6 New Comment:
I didn't say var is null, I said var is false. From the documentation you pasted, the only case when count should return anything other than 0 is if the var is an array or implements the Countable interface. How does false apply to either one of them? Previous Comments: ------------------------------------------------------------------------ [2008-10-16 22:50:30] [EMAIL PROTECTED] Sorry, but your problem does not imply a bug in PHP itself. For a list of more appropriate places to ask for help using PHP, please visit http://www.php.net/support.php as this bug system is not the appropriate forum for asking support questions. Due to the volume of reports we can not explain in detail here why your report is not a bug. The support channels will be able to provide an explanation for you. Thank you for your interest in PHP. >From the documentation on count. If var is not an array or an object with implemented Countable interface, 1 will be returned. There is one exception, if var is NULL, 0 will be returned. You probably want to look at empty() to see if it has any elements rather than use count(). ------------------------------------------------------------------------ [2008-10-16 22:31:09] dmitryshw at hotmail dot com 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. ------------------------------------------------------------------------ [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
