mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
Documentation Bug #13568. Added qualification for conditional function declarations.
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@106123 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
ff2ece55ad
commit
2d81249fec
1 changed files with 72 additions and 2 deletions
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.28 $ -->
|
||||
<!-- $Revision: 1.29 $ -->
|
||||
<chapter id="functions">
|
||||
<title>Functions</title>
|
||||
|
||||
|
@ -37,8 +37,78 @@ function foo ($arg_1, $arg_2, ..., $arg_n)
|
|||
</simpara>
|
||||
<simpara>
|
||||
In PHP 3, functions must be defined before they are referenced. No
|
||||
such requirement exists in PHP 4.
|
||||
such requirement exists in PHP 4. <emphasis>Except</emphasis> when
|
||||
a function is conditionally defined such as shown in the two examples
|
||||
below.
|
||||
</simpara>
|
||||
<para>
|
||||
When a function is defined in a conditional manner such as the two
|
||||
examples shown. Its definition must be processed <emphasis>prior</emphasis>
|
||||
to being called.
|
||||
<example>
|
||||
<title>Conditional functions</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
$makefoo = true;
|
||||
|
||||
/* We can't call foo() from here
|
||||
since it doesn't exist yet,
|
||||
but we can call bar() */
|
||||
|
||||
bar();
|
||||
|
||||
if ($makefoo) {
|
||||
function foo ()
|
||||
{
|
||||
echo "I don't exist until program execution reaches me.\n";
|
||||
}
|
||||
}
|
||||
|
||||
/* Now we can safely call foo()
|
||||
since $makefoo evaluated to true */
|
||||
|
||||
if ($makefoo) foo();
|
||||
|
||||
function bar() {
|
||||
{
|
||||
echo "I exist immediately upon program start.\n";
|
||||
}
|
||||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
<example>
|
||||
<title>Functions within functions</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
function foo()
|
||||
{
|
||||
function bar()
|
||||
{
|
||||
echo "I don't exist until foo() is called.\n";
|
||||
}
|
||||
}
|
||||
|
||||
/* We can't call bar() yet
|
||||
since it doesn't exist. */
|
||||
|
||||
foo();
|
||||
|
||||
/* Now we can call bar(),
|
||||
foo()'s processesing has
|
||||
made it accessable. */
|
||||
|
||||
bar();
|
||||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</para>
|
||||
<simpara>
|
||||
PHP does not support function overloading, nor is it possible to
|
||||
undefine or redefine previously-declared functions.
|
||||
|
|
Loading…
Reference in a new issue