cvs: phpdoc-zh /language functions.xml variables.xml
| From: | Gregory Song | Date: | Sat, 28 Dec 2002 08:47:10 +0000 |
| Subject: | cvs: phpdoc-zh /language functions.xml variables.xml | ||
| Groups: | php.doc.zh | ||
| Request: | Send a blank email to doc-zh+get-943@lists.php.net to get a copy of this message | ||
gregory Sat Dec 28 03:47:10 2002 EDT
Modified files:
/phpdoc-zh/language functions.xml variables.xml
Log:
Up to date with the En version.
Index: phpdoc-zh/language/functions.xml
diff -u phpdoc-zh/language/functions.xml:1.12 phpdoc-zh/language/functions.xml:1.13
--- phpdoc-zh/language/functions.xml:1.12 Mon Oct 14 04:17:27 2002
+++ phpdoc-zh/language/functions.xml Sat Dec 28 03:47:09 2002
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.12 $ -->
-<!-- $Author: yincheng $ -->
-<!-- EN-Revision: 1.28 Maintainer: verdana Status: ready -->
+<!-- $Revision: 1.13 $ -->
+<!-- $Author: gregory $ -->
+<!-- EN-Revision: 1.31 Maintainer: verdana Status: ready -->
+<!-- CREDITS: Gregory -->
<chapter id="functions">
<title>º¯Êý</title>
@@ -37,8 +38,74 @@
</simpara>
<simpara>
ÔÚ PHP 3 ÖУ¬º¯Êý±ØÐëÔÚ±»µ÷ÓÃ֮ǰ¶¨Òå¡£¶ø PHP 4
Ôò²»ÔÙÓÐÕâÑùµÄ
- Ìõ¼þ¡£
+
Ìõ¼þ¡£<emphasis>³ý·Ç</emphasis>º¯ÊýÈçÒÔÏÂÁ½¸ö·¶ÀýÖÐÓÐÌõ¼þµÄ¶¨Òå¡£
</simpara>
+ <para>
+
Èç¹ûÒ»¸öº¯ÊýÒÔÒÔÏÂÁ½¸ö·¶ÀýµÄ·½Ê½ÓÐÌõ¼þµÄ¶¨Ò壬Æä¶¨Ò屨ÐëÔÚµ÷ÓÃ<emphasis>֮ǰ</emphasis>Íê³É¡£
+ <example>
+ <title>ÓÐÌõ¼þµÄº¯Êý</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>º¯ÊýÖеĺ¯Êý</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
²»Ö§³Öº¯ÊýÖØÔØ£¬¿ÉÄÜÒ²²»Ö§³ÖÈ¡Ïû¶¨Òå»òÕßÖØ¶¨ÒåÒÑÉùÃ÷µÄº¯Êý¡£
</simpara>
@@ -305,12 +372,7 @@
ÓÃÓÚʵÏֻص÷º¯Êý£¬º¯Êý±íµÈµÈ¡£
</para>
<para>
- ±äÁ¿º¯Êý²»ÄÜÓÃÓÚÓïÑԽṹ£¬ÀýÈç
<function>echo</function>£¬
- <function>unset</function>£¬<function>isset</function>£¬
- <function>empty</function> ºÍ <function>include</function>¡£
- ¾¡¹ÜÈç´Ë£¬½á¹¹ <function>print</function>
È´ÊǸöÀýÍ⣬¿ÉÒÔÔËÐС£
- ÕâÊÇ PHP º¯ÊýºÍÓïÑԽṹ֮¼äµÄÖ÷Òª²»Í¬Ö®Ò»¡£
-
+ ±äÁ¿º¯Êý²»ÄÜÓÃÓÚÓïÑԽṹ£¬ÀýÈç
<function>echo</function>¡¢<function>print</function>¡¢<function>unset</function>¡¢<function>isset</function>¡¢<function>empty</function>¡¢<function>include</function>¡¢<function>require</function>
ÒÔ¼°ÀàËÆµÄÓï¾ä¡£ÄúÐèҪʹÓÃÄú×Ô¼ºµÄÍâ¿Çº¯ÊýÀ´½«ÕâЩ½á¹¹ÓÃ×÷±äÁ¿º¯Êý¡£
</para>
<para>
<example>
@@ -328,18 +390,57 @@
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>
+
Äú»¹¿ÉÒÔÀûÓñäÁ¿º¯ÊýµÄÌØÐÔÀ´µ÷ÓÃÒ»¸ö¶ÔÏóµÄ·½·¨¡£
+ <example>
+ <title>±äÁ¿·½·¨·¶Àý</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>
- Ïà¹ØÄÚÈݲο¼ <link linkend="language.variables.variable">
- ±äÁ¿µÄ±äÁ¿</link> ºÍ <function>function_exists</function>.
+ Çë²ÎÔÄ <function>call_user_func</function>¡¢<link
linkend="language.variables.variable">±äÁ¿±äÁ¿</link> ºÍ
<function>function_exists</function>¡£
</para>
</sect1>
Index: phpdoc-zh/language/variables.xml
diff -u phpdoc-zh/language/variables.xml:1.4 phpdoc-zh/language/variables.xml:1.5
--- phpdoc-zh/language/variables.xml:1.4 Wed Oct 9 02:48:07 2002
+++ phpdoc-zh/language/variables.xml Sat Dec 28 03:47:09 2002
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.4 $ -->
+<!-- $Revision: 1.5 $ -->
<!-- $Author: gregory $ -->
-<!-- EN-Revision: 1.54 Maintainer: verdana Status: -->
+<!-- EN-Revision: 1.56 Maintainer: verdana Status: -->
<!-- CREDITS: Gregory -->
<chapter id="language.variables">
<title>±äÁ¿</title>
@@ -85,7 +85,33 @@
</programlisting>
</informalexample>
</para>
+ <para>
+ ÔÚ´¦Àí×Ö·û±äÁ¿µÄËãÊýÔËËãʱ£¬PHP ÑØÏ®ÁË Perl
µÄϰ¹ß£¬¶ø·Ç C µÄ¡£ÀýÈ磬ÔÚ Perl ÖÐ 'Z'+1 ½«µÃµ½
'AA'£¬¶øÔÚ C ÖУ¬'Z'+1 ½«µÃµ½ '[' { ord('Z')
== 90, ord('[') == 91 )¡£
+ <example>
+ <title>Éæ¼°×Ö·û±äÁ¿µÄËãÊýÔËËã</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+$i = 'W';
+for($n=0; $n<6; $n++)
+ echo ++$i . "\n";
+
+/*
+ Produces the output similar to the following:
+
+X
+Y
+Z
+AA
+AB
+AC
+*/
+?>
+]]>
+ </programlisting>
+ </example>
+ </para>
</sect1>
<sect1 id="language.variables.predefined">
@@ -116,6 +142,13 @@
´Ó PHP 4.1.0 ¿ªÊ¼£¬PHP
ÌṩÁËÒ»Ì׸½¼ÓµÄÔ¤¶¨Êý×飬ÕâЩÊý×é±äÁ¿°üº¬ÁËÀ´×Ô Web
·þÎñÆ÷£¨Èç¹û¿ÉÓã©£¬ÔËÐл·¾³£¬ºÍÓû§ÊäÈëµÄÊý¾Ý¡£ÕâЩÊý×é·Ç³£Ìرð£¬ËüÃÇÔÚÈ«¾Ö·¶Î§ÄÚ×Ô¶¯ÉúЧ£¬ÀýÈ磬ÔÚÈκη¶Î§ÄÚ×Ô¶¯ÉúЧ¡£Îª´Ë£¬ËüÃdz£ÒòÊÇ
"autoglobals" »òÕß "superglobals" ¶øÎÅÃû¡££¨PHP
ÖÐÉÐÇÒûÓÐÒ»ÖÖ¿ÉʹÓû§×Ô¶¨Ò峬¼¶È«¾Ö±äÁ¿µÄ»úÖÆ£©³¬¼¶È«¾Ö±äÁ¿ÂÞÁÐÓÚÏÂÎÄÖУ»µ«ÊÇΪÁ˵õ½ËüÃǵÄÄÚÈݺ͹ØÓÚ
PHP Ô¤¶¨Òå±äÁ¿µÄ½øÒ»²½µÄÌÖÂÛÒÔ¼°ËüÃǵı¾ÖÊ£¬Çë²ÎÔÄ
<link
linkend="reserved.variables">Ô¤¶¨Òå±äÁ¿</link>¡£¶øÇÒ£¬ÄãÒ²½«×¢Òâµ½¾ÉµÄµØÔ¤¶¨ÒåÊý×飨<varname>$HTTP_*_VARS</varname>£©ÈԾɴæÔÚ¡£
</simpara>
+ <note>
+ <title>±äÁ¿±äÁ¿</title>
+ <para>
+ ³¬¼¶È«¾Ö±äÁ¿²»Äܱ»ÓÃ×÷<link
linkend="language.variables.variable">±äÁ¿±äÁ¿</link>.
+ </para>
+ </note>
+
<para>
Èç¹ûijЩ <link linkend="ini.variables-order">variables_order</link>
ÖеıäÁ¿Ã»ÓÐÉ趨£¬ËüÃǵĶÔÓ¦µÄ PHP
Ô¤¶¨ÒåÊý×éÒ²Êǿյġ£
</para>