pollita         Thu Nov 28 15:43:00 2002 EDT

  Modified files:              
    /phpdoc/en/language functions.xml 
  Log:
  Documentation Bug #13568.  Added qualification for conditional function declarations.
  
  
Index: phpdoc/en/language/functions.xml
diff -u phpdoc/en/language/functions.xml:1.28 phpdoc/en/language/functions.xml:1.29
--- phpdoc/en/language/functions.xml:1.28       Mon Jul  8 07:40:02 2002
+++ phpdoc/en/language/functions.xml    Thu Nov 28 15:43:00 2002
@@ -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 @@
    </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.



-- 
PHP Documentation Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to