Add some words about non-scalar default values

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@160135 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Alexander Voytsekhovskyy 2004-05-31 08:03:30 +00:00
parent 9801989e86
commit 88f5107e6e

View file

@ -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 cappuccino.
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.