Wouldn't saying
<refpurpose>Count elements in an array or properties in an object</refpurpose> be better to say? I know it's explained further on, but to me saying the thing about properties aswell gives you the exact definition of what the function does, in short.


- Tul
Aidan Lister wrote:
aidan           Tue Nov  2 18:41:00 2004 EDT

Modified files: /phpdoc/en/reference/array/functions count.xml Log:
Fixed typo in last commit (count not coun). Added further examples. Used docbook markup appropriately.
http://cvs.php.net/diff.php/phpdoc/en/reference/array/functions/count.xml?r1=1.13&r2=1.14&ty=u
Index: phpdoc/en/reference/array/functions/count.xml
diff -u phpdoc/en/reference/array/functions/count.xml:1.13 phpdoc/en/reference/array/functions/count.xml:1.14
--- phpdoc/en/reference/array/functions/count.xml:1.13 Mon Nov 1 16:11:40 2004
+++ phpdoc/en/reference/array/functions/count.xml Tue Nov 2 18:41:00 2004
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.13 $ -->
+<!-- $Revision: 1.14 $ -->
<!-- splitted from ./en/functions/array.xml, last change in rev 1.2 -->
<refentry id="function.count">
<refnamediv>
<refname>count</refname>
- <refpurpose>Count elements in a variable</refpurpose>
+ <refpurpose>Count elements in an array or an object</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
@@ -15,20 +15,23 @@
</methodsynopsis>
<para>
Returns the number of elements in <parameter>var</parameter>,
- which is typically an <type>array</type> (since anything other than objects - will have one element).
+ which is typically an <type>array</type>, since anything other than objects + will have one element.
</para>
<para>
- For objects it returns the number of non static properties not taking
- visibility into account. If you have SPL starting from PHP 5.1 you can - hook into coun() by implementing interface Countable. That interface
- has exactly one method named count() which delivers the return value
- for the count() function.
- </para>
- <para>
- If <parameter>var</parameter> is not an array, <literal>1</literal> will
- be returned (exception: <literal>count(&null;)</literal> equals
- <literal>0</literal>).
+ For objects <function>count</function> will return the number of non static
+ properties, not taking visibility into account. 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,
+ <function>count</function>, which returns the return value for the
+ <function>count</function> function.
+ </para>
+ <para>
+ If <parameter>var</parameter> is not an array or an object,
+ <literal>1</literal> will be returned.
+ There is one exception, if <parameter>var</parameter> is &null;,
+ <literal>0</literal> will be returned.
</para>
<note>
<simpara>
@@ -53,7 +56,7 @@
</para>
</caution>
<para>
- Please see the <link linkend="language.types.array">Arrays</link>
+ Please see the <link linkend="language.types.array">Array</link>
section of the manual for a detailed explanation of how arrays
are implemented and used in PHP.
</para>
@@ -61,7 +64,6 @@
<example>
<title><function>count</function> example</title>
<programlisting role="php">
- <!-- TODO: examples about count(null), count(false), count(object).. -->
<![CDATA[
<?php
$a[0] = 1;
@@ -75,6 +77,18 @@
$b[10] = 11;
$result = count($b);
// $result == 3;
+
+$result = count(null);
+// $result == 0;
+
+$result = count(false);
+// $result == 1;
+
+$obj = new StdClass;
+$obj->foo = 'A property';
+$obj->bar = 'Another property';
+$result = count($obj);
+// $result == 2;
?>
]]>
</programlisting>
@@ -102,12 +116,6 @@
</programlisting>
</example>
</para>
- <note>
- <para>
- The <function>sizeof</function> function is an
- <link linkend="aliases">alias</link> for <function>count</function>.
- </para>
- </note>
<para>
See also <function>is_array</function>,
<function>isset</function>, and

Reply via email to