#31977 [Opn->Csd]: count() doesnt count class members properly
| From: | vrana@php.net | Date: | Sun, 20 Mar 2005 10:16:42 +0000 |
| Subject: | #31977 [Opn->Csd]: count() doesnt count class members properly | ||
| References: | 1 | Groups: | php.doc |
| Request: | Send a blank email to phpdoc+get-969367028@lists.php.net to get a copy of this message | ||
ID: 31977
Updated by: vrana@php.net
Reported By: jmarbas at hotmail dot com
-Status: Open
+Status: Closed
Bug Type: Documentation problem
Operating System: *
PHP Version: 4CVS, 5CVS (2005-02-22)
New Comment:
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.
Thank you for the report, and for helping us make our documentation
better.
Previous Comments:
------------------------------------------------------------------------
[2005-02-25 15:47:39] tony2001@php.net
The documentation is wrong: count() should return 1 for any variable
that is not an array or NULL.
------------------------------------------------------------------------
[2005-02-15 03:01:45] jmarbas at hotmail dot com
Description:
------------
When I try to count the number of non-static members of an object with
the count() function, I always get a count of 1. The code below shows
both a user defined class and the standard class(StdClass) instances
with more than 1 member variable each but the count() still comes out
to 1.
Reproduce code:
---------------
class jerry{
public $foo='A property';
public $bar='Another property';
}
$obj1 = new jerry();
echo $obj1->foo."\n";
echo $obj1->bar."\n";
printf("The count is %d\n",count($obj1));
$obj = new StdClass;
$obj->foo='A property';
$obj->bar='Another property';
$obj->bleh='asdf';
echo $obj->foo."\n";
echo $obj->bar."\n";
echo $obj->bleh."\n";
printf("The count is %d\n",count($obj));
Expected result:
----------------
I expect the count() function to count all non-static member variables
just like it says in the count() description on php.net
Actual result:
--------------
The actual count() is 1 for both objects in the code pasted above.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=31977&edit=1