note 73968 deleted from function.count by bjori
| From: | bjori@php.net | Date: | Tue, 03 Apr 2007 12:02:03 +0000 |
| Subject: | note 73968 deleted from function.count by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-125035@lists.php.net to get a copy of this message | ||
Note Submitter: bobo at newage dot com
----
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