Mombu the Php Forum sponsored links

Go Back   Mombu the Php Forum > Php > #31977 : count() doesnt count class members properly
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 8th September 19:04
php-bugs
External User
 
Posts: 1
Default #31977 : count() doesnt count class members properly



From: jmarbas at hotmail dot com
Operating system: Windows XP
PHP version: 5.0.3
PHP Bug Type: Class/Object related
Bug description: count() doesnt count class members properly

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 bug report at http://bugs.php.net/?id=31977&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=31977&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=31977&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=31977&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=31977&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=31977&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=31977&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=31977&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=31977&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=31977&r=support
Expected behavior: http://bugs.php.net/fix.php?id=31977&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=31977&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=31977&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=31977&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=31977&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=31977&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=31977&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=31977&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=31977&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=31977&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=31977&r=mysqlcfg
  Reply With Quote


  sponsored links


2 9th September 20:59
External User
 
Posts: 1
Default #31977 : count() doesnt count class members properly



ID: 31977
Updated by: sniper@php.net
Reported By: jmarbas at hotmail dot com
-Status: Open
+Status: Verified
Bug Type: Class/Object related
-Operating System: Windows XP
+Operating System: *
-PHP Version: 5.0.3
+PHP Version: 4CVS, 5CVS (2005-02-22)


Previous Comments:
------------------------------------------------------------------------

[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
  Reply With Quote


  sponsored links


Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666