goba            Sun Dec  1 05:44:46 2002 EDT

  Modified files:              
    /phpdoc/en/language functions.xml 
  Log:
  Adding explanation about using wrapper functions
  instead of the language constructs. Also reworded
  the language construct's list a bit, so it indicates
  that there are more constructs not working. Added a
  new object example on how to use variable funcitons
  inside objects.
  
  
Index: phpdoc/en/language/functions.xml
diff -u phpdoc/en/language/functions.xml:1.29 phpdoc/en/language/functions.xml:1.30
--- phpdoc/en/language/functions.xml:1.29       Thu Nov 28 15:43:00 2002
+++ phpdoc/en/language/functions.xml    Sun Dec  1 05:44:46 2002
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.29 $ -->
+<!-- $Revision: 1.30 $ -->
  <chapter id="functions">
   <title>Functions</title>
 
@@ -403,9 +403,12 @@
    </para>
    <para>
     Variable functions won't work with language constructs such 
-    as <function>echo</function>, <function>unset</function>,
-    <function>isset</function>, <function>empty</function>, 
-    <function>include</function> and <function>print</function>.
+    as <function>echo</function>, <function>print</function>,
+    <function>unset</function>, <function>isset</function>,
+    <function>empty</function>, <function>include</function>,
+    <function>require</function> and the like. You need to use
+    your own wrapper function to use any of these constructs
+    as variable functions.
    </para>
    <para>
     <example>
@@ -423,22 +426,62 @@
     echo "In bar(); argument was '$arg'.<br>\n";
 }
 
+// This is a wrapper function around echo
+function echoit($string)
+{
+    echo $string;
+}
+
 $func = 'foo';
-$func();
+$func();        // This calls foo()
+
 $func = 'bar';
-$func('test');
+$func('test');  // This calls bar()
+
+$func = 'echoit';
+$func('test');  // This calls echoit()
+?>
+]]>
+     </programlisting>
+    </example>
+   </para>
+   <para>
+    You can also call an objects method by using the variable functions
+    feature.
+    <example>
+     <title>Variable method example</title>
+     <programlisting role="php">
+<![CDATA[
+<?php
+class Foo
+{
+    function Var()
+    {
+        $name = 'Bar';
+        $this->$name(); // This calls the Bar() method
+    }
+    
+    function Bar()
+    {
+        echo "This is Bar";
+    }
+}
+
+$foo = new Foo();
+$funcname = "Var";
+$foo->$varname();   // This calls $foo->Var()
+
 ?>
 ]]>
      </programlisting>
     </example>
    </para>
    <para>
-    See also <link linkend="language.variables.variable">
+    See also <function>call_user_func</function>,
+    <link linkend="language.variables.variable">
     variable variables</link> and <function>function_exists</function>.
    </para>
-
   </sect1>
-
  </chapter>
  
 <!-- Keep this comment at the end of the file



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

Reply via email to