cvs: /phpdoc/language functions.sgml

From: Date: Tue, 16 Nov 1999 02:50:24 +0000
Subject: cvs: /phpdoc/language functions.sgml
Groups: php.dev 
Request: Send a blank email to php-dev+get-12592@lists.php.net to get a copy of this message
cslawi Mon Nov 15 21:50:24 1999 EDT Modified files: /phpdoc/language functions.sgml Log: Document variable functions. Alphabetization fix. Note that in PHP3 you need to define functions before using them, but that in PHP4, you don't. Index: phpdoc/language/functions.sgml diff -u phpdoc/language/functions.sgml:1.6 phpdoc/language/functions.sgml:1.7 --- phpdoc/language/functions.sgml:1.6 Wed Oct 20 18:52:31 1999 +++ phpdoc/language/functions.sgml Mon Nov 15 21:50:21 1999 @@ -21,38 +21,12 @@ functions and <link linkend="keyword.class">class</link> definitions.</simpara> - <simpara> - Functions must be defined before they are referenced.</simpara></sect1> - - <sect1 id="functions.returning-values"> - <title>Returning values</title> - - <para> - Values are returned by using the optional return statement. Any - type may be returned, including lists and objects. - - <informalexample> - <programlisting> -function square ($num) { - return $num * $num; -} -echo square (4); // outputs '16'. - </programlisting> - </informalexample></para> - - <para> - You can't return multiple values from a function, but similar - results can be obtained by returning a list. + <simpara> + In PHP3, functions must be defined before they are referenced. No + such requirement exists in PHP4. + </simpara> + </sect1> - <informalexample> - <programlisting> -function small_numbers() { - return array (0, 1, 2); -} -list ($zero, $one, $two) = small_numbers(); - </programlisting> - </informalexample></para></sect1> - <sect1 id="functions.arguments"> <title>Function arguments</title> @@ -195,8 +169,40 @@ <screen> Making a bowl of acidophilus raspberry. - </screen></para></sect2></sect1> + </screen> + </para> + </sect2> + </sect1> + <sect1 id="functions.returning-values"> + <title>Returning values</title> + + <para> + Values are returned by using the optional return statement. Any + type may be returned, including lists and objects. + + <informalexample> + <programlisting> +function square ($num) { + return $num * $num; +} +echo square (4); // outputs '16'. + </programlisting> + </informalexample></para> + + <para> + You can't return multiple values from a function, but similar + results can be obtained by returning a list. + + <informalexample> + <programlisting> +function small_numbers() { + return array (0, 1, 2); +} +list ($zero, $one, $two) = small_numbers(); + </programlisting> + </informalexample></para></sect1> + <sect1 id="functions.old-syntax"> <title><literal>old_function</literal></title> @@ -217,7 +223,43 @@ this limitation by writing a wrapper function (in normal PHP3 form) to call the <literal>old_function</literal>. </para> - </warning></sect1> + </warning> + </sect1> + + <sect1 id="functions.variable-functions"> + <title>Variable functions</title> + + <para> + PHP supports the concept of variable functions. This means that if + a variable name has parentheses appended to it, PHP will look for + a function with the same name as whatever the variable evaluates + to, and will attempt to execute it. Among other things, this can + be used to implement callbacks, function tables, and so forth. + </para> + + <para> + <example> + <title>Variable function example</title> + <programlisting> +&lt;?php +function foo() { + echo "In foo()&lt;br&gt;\n"; +} + +function bar( $arg = '' ) { + echo "In bar(); argument was '$arg'.&lt;br&gt;\n"; +} + +$func = 'foo'; +$func(); +$func = 'bar'; +$func( 'test' ); +?&gt; + </programlisting> + </example> + </para> + + </sect1> </chapter>

« previous php.dev (#12592) next »