note 105713 added to function.count
| From: | mike dot mackintosh at angrystatic dot com | Date: | Thu, 08 Sep 2011 17:31:06 +0000 |
| Subject: | note 105713 added to function.count | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-183052@lists.php.net to get a copy of this message | ||
If you try to do a sizeof or count with an object, it will always return 1 if the object is not
null.
You need to type cast the object as an array for it to count correctly.
ex:
$obj->foo = 'fu';
$obj->bar = $fooBar();
echo count($obj); //returns 1
echo count( (array) $obj); // returns 2
----
Server IP: 69.147.83.197
Probable Submitter: 199.74.155.50
----
Manual Page -- http://www.php.net/manual/en/function.count.php
Edit -- https://master.php.net/note/edit/105713
Del: integrated -- https://master.php.net/note/delete/105713/integrated
Del: useless -- https://master.php.net/note/delete/105713/useless
Del: bad code -- https://master.php.net/note/delete/105713/bad+code
Del: spam -- https://master.php.net/note/delete/105713/spam
Del: non-english -- https://master.php.net/note/delete/105713/non-english
Del: in docs -- https://master.php.net/note/delete/105713/in+docs
Del: other reasons-- https://master.php.net/note/delete/105713
Reject -- https://master.php.net/note/reject/105713
Search -- https://master.php.net/manage/user-notes.php