note 108623 added to function.count
| From: | kemal dot delalic at gmail dot com | Date: | Fri, 11 May 2012 11:47:36 +0000 |
| Subject: | note 108623 added to function.count | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-187938@lists.php.net to get a copy of this message | ||
Since anything else than array / Countable makes no sense in this function, here's a
"fixed" version:
class arr {
public static function count($array, $mode = COUNT_NORMAL)
{
// Definitely an array
if (is_array($array))
return count($array, $mode);
// Countable
if (is_object($array) AND $array instanceof Countable)
return count($array, $mode);
return NULL;
}
}
This allows
if (arr::count(FALSE) > 0) to evaluate to FALSE.
----
Server IP: 69.147.83.197
Probable Submitter: 188.127.114.82
----
Manual Page -- http://www.php.net/manual/en/function.count.php
Edit -- https://master.php.net/note/edit/108623
Del: integrated -- https://master.php.net/note/delete/108623/integrated
Del: useless -- https://master.php.net/note/delete/108623/useless
Del: bad code -- https://master.php.net/note/delete/108623/bad+code
Del: spam -- https://master.php.net/note/delete/108623/spam
Del: non-english -- https://master.php.net/note/delete/108623/non-english
Del: in docs -- https://master.php.net/note/delete/108623/in+docs
Del: other reasons-- https://master.php.net/note/delete/108623
Reject -- https://master.php.net/note/reject/108623
Search -- https://master.php.net/manage/user-notes.php