mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
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:
parent
9801989e86
commit
88f5107e6e
1 changed files with 22 additions and 2 deletions
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue