|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-07-16 00:32 UTC] kalle@php.net
[2008-07-16 11:07 UTC] helly@php.net
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 26 22:00:01 2025 UTC |
Description: ------------ When doing count($var) where $var is not an array, the return = 1. The problem is when you're doing a check in your code: if (count($var) > 0){ //do something } This will evaluate as true if $var is not an array. This is a problem if you are doing this: if (count($var) > 0){ sort($var); // anything that requires $var to be an array } If there is anything in that if statement that requires $var to be an array, there will be a fatal error. I know you can also add an is_array check in there, but that is non-obvious and shouldn't be necessary. Really, if $var is not an array, count($var) should return false or null, or at least a -1 Reproduce code: --------------- $var = "foo"; if (count($var) > 0){ sort($var); } else { echo "The value of var is not greater than zero"; } Expected result: ---------------- The value of var is not greater than zero Actual result: -------------- Warning: sort() expects parameter 1 to be array, string given