From 8747a04d26e260f346bec573318a76b6dafc31e0 Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Sun, 20 Mar 2005 10:16:34 +0000 Subject: [PATCH] Doesn't count object members (bug #31977) git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@182485 c90b9560-bf6c-de11-be94-00142212c4b1 --- reference/array/functions/count.xml | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/reference/array/functions/count.xml b/reference/array/functions/count.xml index 1ed28cd40e..59162f5d2d 100644 --- a/reference/array/functions/count.xml +++ b/reference/array/functions/count.xml @@ -1,5 +1,5 @@ - + @@ -15,12 +15,11 @@ Returns the number of elements in var, - which is typically an array, since anything other than objects + which is typically an array, since anything other will have one element. - For objects count will return the number of non static - properties, not taking visibility into account. If you have + For objects, if you have SPL installed, you can hook into count by implementing interface Countable. The interface has exactly one method, @@ -28,7 +27,8 @@ count function. - If var is not an array or an object, + If var is not an array or an object with + implemented Countable interface, 1 will be returned. There is one exception, if var is &null;, 0 will be returned. @@ -76,19 +76,13 @@ $b[0] = 7; $b[5] = 9; $b[10] = 11; $result = count($b); -// $result == 3; +// $result == 3 $result = count(null); -// $result == 0; +// $result == 0 $result = count(false); -// $result == 1; - -$obj = new StdClass; -$obj->foo = 'A property'; -$obj->bar = 'Another property'; -$result = count($obj); -// $result == 2; +// $result == 1 ?> ]]> @@ -97,7 +91,7 @@ $result = count($obj); - recursive <function>count</function> example (PHP >= 4.2.0) + Recursive <function>count</function> example (PHP >= 4.2.0) array('orange', 'banana', 'apple'), 'veggie' => array('carrot', 'collard', 'pea')); // recursive count -echo count($food, COUNT_RECURSIVE); // output 8 +echo count($food, COUNT_RECURSIVE); // output 8 // normal count -echo count($food); // output 2 +echo count($food); // output 2 ?> ]]>