Doesn't count object members (bug #31977)

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@182485 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Jakub Vrana 2005-03-20 10:16:34 +00:00
parent aaa51f71c7
commit 8747a04d26

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.15 $ -->
<!-- $Revision: 1.16 $ -->
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
<refentry id="function.count">
<refnamediv>
@ -15,12 +15,11 @@
</methodsynopsis>
<para>
Returns the number of elements in <parameter>var</parameter>,
which is typically an <type>array</type>, since anything other than objects
which is typically an <type>array</type>, since anything other
will have one element.
</para>
<para>
For objects <function>count</function> will return the number of non static
properties, not taking visibility into account. If you have
For objects, if you have
<link linkend="ref.spl">SPL</link> installed, you can hook into
<function>count</function> by implementing interface
<literal>Countable</literal>. The interface has exactly one method,
@ -28,7 +27,8 @@
<function>count</function> function.
</para>
<para>
If <parameter>var</parameter> is not an array or an object,
If <parameter>var</parameter> is not an array or an object with
implemented <literal>Countable</literal> interface,
<literal>1</literal> will be returned.
There is one exception, if <parameter>var</parameter> is &null;,
<literal>0</literal> 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
?>
]]>
</programlisting>
@ -97,7 +91,7 @@ $result = count($obj);
<para>
<example>
<title>
recursive <function>count</function> example (PHP &gt;= 4.2.0)
Recursive <function>count</function> example (PHP &gt;= 4.2.0)
</title>
<programlisting role="php">
<![CDATA[
@ -106,10 +100,10 @@ $food = array('fruits' => 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
?>
]]>