note 73968 added to function.count
| From: | bobo at newage dot com | Date: | Sun, 18 Mar 2007 20:59:29 +0000 |
| Subject: | note 73968 added to function.count | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-124578@lists.php.net to get a copy of this message | ||
count() does not work if you use it on an array that contains objects. sizeof() DOES WORK, although
the manual states that it is just an alias for count().
Example:
class A{
private $arr_of_objs = array();
public function __construct(){
$arr_of_objs[0] = new SomeClass();
$arr_of_objs[1] = new SomeClass();
}
public function getNumOfObjs(){
count($this->arr_of_objs); // No luck!!! This returns 0.
echo "<br>";
sizeof($this->arr_of_objs); // This returns 2.
}
}
$myObj = new A();
$myObj->getNumOfObjs();
Output:
0
2
----
Server IP: 87.238.162.147
Probable Submitter: 88.147.13.138
----
Manual Page -- http://www.php.net/manual/en/function.count.php
Edit -- https://master.php.net/note/edit/73968
Del: integrated -- https://master.php.net/note/delete/73968/integrated
Del: useless -- https://master.php.net/note/delete/73968/useless
Del: bad code -- https://master.php.net/note/delete/73968/bad+code
Del: spam -- https://master.php.net/note/delete/73968/spam
Del: non-english -- https://master.php.net/note/delete/73968/non-english
Del: in docs -- https://master.php.net/note/delete/73968/in+docs
Del: other reasons-- https://master.php.net/note/delete/73968
Reject -- https://master.php.net/note/reject/73968
Search -- https://master.php.net/manage/user-notes.php