young Mon May 31 04:03:30 2004 EDT
Modified files:
/phpdoc/en/language functions.xml
Log:
Add some words about non-scalar default values
http://cvs.php.net/diff.php/phpdoc/en/language/functions.xml?r1=1.47&r2=1.48&ty=u
Index: phpdoc/en/language/functions.xml
diff -u phpdoc/en/language/functions.xml:1.47 phpdoc/en/language/functions.xml:1.48
--- phpdoc/en/language/functions.xml:1.47 Wed May 5 16:19:50 2004
+++ phpdoc/en/language/functions.xml Mon May 31 04:03:30 2004
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.47 $ -->
+<!-- $Revision: 1.48 $ -->
<chapter id="language.functions">
<title>Functions</title>
@@ -249,7 +249,27 @@
Making a cup of espresso.
</screen>
</para>
-
+ <para>
+ Also PHP allows you to use arrays and special type NULL as
+ default values, for example:
+ <example>
+ <title>Using non-scalar types as default values</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+function makecoffee ($types = array("cappuccino"), $coffeeMaker = NULL)
+{
+ $device = is_null($coffeeMaker) ? "hands" : $coffeeMaker;
+ return "Making a cup of ".join(", ", $types)." with $device.\n";
+}
+echo makecoffee ();
+echo makecoffee (array("cappuccino", "lavazza"), "teapot");
+?>
+]]>
+ </programlisting>
+ </example>
+
+ </para>
<simpara>
The default value must be a constant expression, not (for
example) a variable, a class member or a function call.