cvs: phpdoc-zh /language variables.xml
| From: | liuming | Date: | Mon, 10 Feb 2003 09:58:50 +0000 |
| Subject: | cvs: phpdoc-zh /language variables.xml | ||
| Groups: | php.doc.zh | ||
| Request: | Send a blank email to doc-zh+get-1023@lists.php.net to get a copy of this message | ||
lm92 Mon Feb 10 04:58:50 2003 EDT
Modified files:
/phpdoc-zh/language variables.xml
Log:
abc
Index: phpdoc-zh/language/variables.xml diff -u phpdoc-zh/language/variables.xml:1.5 phpdoc-zh/language/variables.xml:1.6 --- phpdoc-zh/language/variables.xml:1.5 Sat Dec 28 03:47:09 2002 +++ phpdoc-zh/language/variables.xml Mon Feb 10 04:58:49 2003 @@ -1,11 +1,11 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.5 $ --> -<!-- $Author: gregory $ --> +<!-- $Revision: 1.6 $ --> +<!-- $Author: lm92 $ --> <!-- EN-Revision: 1.56 Maintainer: verdana Status: --> <!-- CREDITS: Gregory --> <chapter id="language.variables"> <title>±äÁ¿</title> - + <sect1 id="language.variables.basics"> <title>»ù´¡</title> @@ -16,7 +16,7 @@ <para> ±äÁ¿ÃûÓë PHP ÖÐÆäËüµÄ±êǩһÑù×ñÑÏàͬµÄ¹æÔò¡£Ò»¸öÓÐЧµÄ±äÁ¿ÃûÓÉ×Öĸ»òÕßÏ»®Ïß¿ªÍ·£¬ºóÃæ¸úÉÏÈÎÒâÊýÁ¿µÄ×Öĸ£¬Êý×Ö£¬»òÕßÏ»®Ïß¡£°´ÕÕÕý³£µÄÕýÔò±í´ïʽ£¬Ëü½«±»±íÊöΪ£º'[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*' </para> - + <note> <simpara> ×ÖĸΪ a-z£¬A-Z£¬ASCII ×Ö·û´Ó 127 µ½ 255 £¨0x7f-0xff£©¡£ @@ -25,7 +25,7 @@ <para> <informalexample> - <programlisting role="php"> + <programlisting role="php"> <![CDATA[ <?php $var = "Bob"; @@ -116,7 +116,7 @@ <sect1 id="language.variables.predefined"> <title>Ô¤¶¨Òå±äÁ¿</title> - + <simpara> PHP ÌṩÁË´óÁ¿µÄÔ¤¶¨Òå±äÁ¿¡£ÓÉÓÚÐí¶à±äÁ¿ÒÀÀµÓÚÔËÐеķþÎñÆ÷µÄ°æ±¾ºÍÉèÖ㬼°ÆäËüÒòËØ£¬ËùÒÔ²¢Ã»ÓÐÏêϸµÄ˵Ã÷Îĵµ¡£Ò»Ð©Ô¤¶¨Òå±äÁ¿ÔÚ PHP ÒÔ<link linkend="features.commandline">ÃüÁîÐÐ</link>ÐÎʽÔËÐÐʱ²¢²»ÉúЧ¡£ÓйØÕâЩ±äÁ¿µÄÏêϸÁÐ±í£¬Çë²ÎÔÄ¡°<link linkend="reserved.variables">±£ÁôµÄÔ¤¶¨Òå±äÁ¿</link>¡±Ò»Õ¡£ </simpara> @@ -125,12 +125,12 @@ <simpara> PHP 4.2.0 ÒÔ¼°ºóÐø°æ±¾ÖУ¬ PHP Ö¸Áî <link linkend="ini.register-globals">register_globals</link> µÄĬÈÏֵΪ - <emphasis>off</emphasis>. ÕâÊÇ PHP µÄÒ»¸öÖ÷Òª±ä»¯¡£Èà register_globals µÄֵΪ <emphasis>off</emphasis> ½«Ó°Ïìµ½Ô¤¶¨Òå±äÁ¿¼¯ÔÚÈ«¾Ö·¶Î§ÄÚµÄÓÐЧÐÔ¡£ÀýÈ磬ΪÁ˵õ½ <varname>DOCUMENT_ROOT</varname> µÄÖµ£¬Ä㽫±ØÐëʹÓà + <emphasis>off</emphasis>. ÕâÊÇ PHP µÄÒ»¸öÖ÷Òª±ä»¯¡£Èà register_globals µÄֵΪ <emphasis>off</emphasis> ½«Ó°Ïìµ½Ô¤¶¨Òå±äÁ¿¼¯ÔÚÈ«¾Ö·¶Î§ÄÚµÄÓÐЧÐÔ¡£ÀýÈ磬ΪÁ˵õ½ <varname>DOCUMENT_ROOT</varname> µÄÖµ£¬Ä㽫±ØÐëʹÓà <varname>$_SERVER['DOCUMENT_ROOT']</varname> ´úÌæ <varname>$DOCUMENT_ROOT</varname>£¬ÓÖÈ磬ʹÓà <varname>$_GET['id']</varname> À´´úÌæ <varname>$id</varname> ´Ó URL <literal>http://www.example.com/test.php?id=3</literal> ÖлñÈ¡ id Öµ£¬Òà»òʹÓà <varname>$_ENV['HOME']</varname> À´´úÌæ <varname>$HOME</varname> »ñÈ¡»·¾³±äÁ¿ HOME µÄÖµ¡£ </simpara> <simpara> - ¸ü¶àÏà¹ØÐÅÏ¢£¬ÇëÔĶÁÅäÖÃÏîÄ¿ <link linkend="ini.register-globals">register_globals</link>£¬Óйذ²È«ÐÔµÄÒ»Õ <link linkend="security.registerglobals">ʹÓà Register Globals</link>£¬ÒÔ¼° PHP <ulink url="&url.php.release4.1.0;">4.1.0</ulink> ºÍ + ¸ü¶àÏà¹ØÐÅÏ¢£¬ÇëÔĶÁÅäÖÃÏîÄ¿ <link linkend="ini.register-globals">register_globals</link>£¬Óйذ²È«ÐÔµÄÒ»Õ <link linkend="security.registerglobals">ʹÓà Register Globals</link>£¬ÒÔ¼° PHP <ulink url="&url.php.release4.1.0;">4.1.0</ulink> ºÍ <ulink url="&url.php.release4.2.0;">4.2.0</ulink> µÄ·¢ÐÐͨ¸æ. </simpara> <simpara> @@ -148,7 +148,7 @@ ³¬¼¶È«¾Ö±äÁ¿²»Äܱ»ÓÃ×÷<link linkend="language.variables.variable">±äÁ¿±äÁ¿</link>. </para> </note> - + <para> Èç¹ûijЩ <link linkend="ini.variables-order">variables_order</link> ÖеıäÁ¿Ã»ÓÐÉ趨£¬ËüÃǵĶÔÓ¦µÄ PHP Ô¤¶¨ÒåÊý×éÒ²Êǿյġ£ </para> @@ -168,7 +168,7 @@ <term><link linkend="reserved.variables.server">$_SERVER</link></term> <listitem> <simpara> - ±äÁ¿ÓÉ Web ·þÎñÆ÷É趨»òÕßÖ±½ÓÓ뵱ǰ½Å±¾µÄÖ´Ðл·¾³Ïà¹ØÁª¡£ÀàËÆÓÚ¾ÉÊý×é <varname>$HTTP_SERVER_VARS</varname> + ±äÁ¿ÓÉ Web ·þÎñÆ÷É趨»òÕßÖ±½ÓÓ뵱ǰ½Å±¾µÄÖ´Ðл·¾³Ïà¹ØÁª¡£ÀàËÆÓÚ¾ÉÊý×é <varname>$HTTP_SERVER_VARS</varname> Êý×飨ÒÀÈ»ÓÐЧ£¬µ«·´¶ÔʹÓã©¡£ </simpara> </listitem> @@ -177,7 +177,7 @@ <term><link linkend="reserved.variables.get">$_GET</link></term> <listitem> <simpara> - ¾ÓÉ HTTP GET ·½·¨Ìá½»ÖÁ½Å±¾µÄ±äÁ¿¡£ÀàËÆÓÚ¾ÉÊý×é <varname>$HTTP_GET_VARS</varname> + ¾ÓÉ HTTP GET ·½·¨Ìá½»ÖÁ½Å±¾µÄ±äÁ¿¡£ÀàËÆÓÚ¾ÉÊý×é <varname>$HTTP_GET_VARS</varname> Êý×飨ÒÀÈ»ÓÐЧ£¬µ«·´¶ÔʹÓã©¡£ </simpara> </listitem> @@ -186,7 +186,7 @@ <term><link linkend="reserved.variables.post">$_POST</link></term> <listitem> <simpara> - ¾ÓÉ HTTP POST ·½·¨Ìá½»ÖÁ½Å±¾µÄ±äÁ¿¡£ÀàËÆÓÚ¾ÉÊý×é <varname>$HTTP_POST_VARS</varname> + ¾ÓÉ HTTP POST ·½·¨Ìá½»ÖÁ½Å±¾µÄ±äÁ¿¡£ÀàËÆÓÚ¾ÉÊý×é <varname>$HTTP_POST_VARS</varname> Êý×飨ÒÀÈ»ÓÐЧ£¬µ«·´¶ÔʹÓã©¡£ </simpara> </listitem> @@ -195,7 +195,7 @@ <term><link linkend="reserved.variables.cookies">$_COOKIE</link></term> <listitem> <simpara> - ¾ÓÉ HTTP Cookies ·½·¨Ìá½»ÖÁ½Å±¾µÄ±äÁ¿¡£ÀàËÆÓÚ¾ÉÊý×é <varname>$HTTP_COOKIE_VARS</varname> + ¾ÓÉ HTTP Cookies ·½·¨Ìá½»ÖÁ½Å±¾µÄ±äÁ¿¡£ÀàËÆÓÚ¾ÉÊý×é <varname>$HTTP_COOKIE_VARS</varname> Êý×飨ÒÀÈ»ÓÐЧ£¬µ«·´¶ÔʹÓã©¡£ </simpara> </listitem> @@ -204,7 +204,7 @@ <term><link linkend="reserved.variables.files">$_FILES</link></term> <listitem> <simpara> - ¾ÓÉ HTTP POST ÎļþÉÏ´«¶øÌá½»ÖÁ½Å±¾µÄ±äÁ¿¡£ÀàËÆÓÚ¾ÉÊý×é <varname>$HTTP_POST_FILES</varname> + ¾ÓÉ HTTP POST ÎļþÉÏ´«¶øÌá½»ÖÁ½Å±¾µÄ±äÁ¿¡£ÀàËÆÓÚ¾ÉÊý×é <varname>$HTTP_POST_FILES</varname> Êý×飨ÒÀÈ»ÓÐЧ£¬µ«·´¶ÔʹÓã©¡£ÏêϸÐÅÏ¢Çë²ÎÔÄ <link linkend="features.file-upload.post-method">POST ·½·¨ÉÏ´«</link>¡£ </simpara> </listitem> @@ -213,7 +213,7 @@ <term><link linkend="reserved.variables.environment">$_ENV</link></term> <listitem> <simpara> - Ö´Ðл·¾³Ìá½»ÖÁ½Å±¾µÄ±äÁ¿¡£ÀàËÆÓÚ¾ÉÊý×é <varname>$HTTP_ENV_VARS</varname> + Ö´Ðл·¾³Ìá½»ÖÁ½Å±¾µÄ±äÁ¿¡£ÀàËÆÓÚ¾ÉÊý×é <varname>$HTTP_ENV_VARS</varname> Êý×飨ÒÀÈ»ÓÐЧ£¬µ«·´¶ÔʹÓã©¡£ </simpara> </listitem> @@ -223,14 +223,14 @@ <listitem> <simpara> ¾ÓÉÈκÎÓû§ÊäÈë»úÖÆÌá½»ÖÁ½Å±¾µÄ±äÁ¿£¬Òò´Ë¸ÃÊý×é²¢²»ÖµµÃÐÅÈΡ£ËùÓаüº¬ÔÚ¸ÃÊý×éÖеıäÁ¿µÄ´æÔÚÓë·ñ - ÒÔ¼°±äÁ¿µÄ˳Ðò¾ù°´ÕÕ &php.ini; ÖÐµÄ <link linkend="ini.variables-order">variables_order</link> + ÒÔ¼°±äÁ¿µÄ˳Ðò¾ù°´ÕÕ &php.ini; ÖÐµÄ <link linkend="ini.variables-order">variables_order</link> ÅäÖÃָʾÀ´¶¨Òå¡£¸ÃÊý×éûÓÐÖ±½ÓÄ£Äâ PHP 4.1.0 µÄÔçÆÚ°æ±¾¡£²ÎÕÕ <function>import_request_variables</function>¡£ </simpara> <note> <simpara> µ±ÔËÐÐÓÚ <link linkend="features.commandline">ÃüÁîÐÐ</link> ģʽʱ£¬Õâ¸öÊý×齫 <emphasis>²»»á</emphasis> °üº¬ <varname>argv</varname> ºÍ <varname>argc</varname> Èë¿Ú£»ËüÃÇÒѾ´æÔÚÓÚÊý×é <varname>$_SERVER</varname> ÖС£ </simpara> - </note> + </note> </listitem> </varlistentry> <varlistentry> @@ -265,17 +265,17 @@ <simpara> ÕâÀï±äÁ¿ <varname>$a</varname> ½«»áÔÚ°üº¬Îļþ <filename>b.inc</filename> ÖÐÉúЧ¡£µ«ÊÇ£¬ÔÚÓû§×Ô¶¨Ò庯ÊýÖУ¬Ò»¸ö¾Ö²¿º¯Êý·¶Î§½«±»ÒýÈë¡£ÈκÎÓÃÓÚº¯ÊýÄÚ²¿µÄ±äÁ¿°´È±Ê¡Çé¿ö½«±»ÏÞÖÆÔÚ¾Ö²¿º¯Êý·¶Î§ÄÚ¡£·¶Àý£º </simpara> - + <informalexample> - <programlisting role="php"> + <programlisting role="php"> <![CDATA[ <?php -$a = 1; /* global scope */ +$a = 1; /* global scope */ function Test() -{ - echo $a; /* reference to local scope variable */ -} +{ + echo $a; /* reference to local scope variable */ +} Test(); ?> @@ -299,7 +299,7 @@ global $a, $b; $b = $a + $b; -} +} Sum(); echo $b; @@ -326,7 +326,7 @@ function Sum() { $GLOBALS["b"] = $GLOBALS["a"] + $GLOBALS["b"]; -} +} Sum(); echo $b; @@ -340,7 +340,7 @@ linkend="language.variables.superglobals">superglobal</link> ±äÁ¿¡£ÒÔÏ·¶ÀýÏÔʾÁË superglobals µÄÓô¦£º </simpara> <para> - + <informalexample> <programlisting role="php"> <![CDATA[ @@ -349,9 +349,9 @@ { // ´ó¶àÊýµÄÔ¤¶¨Òå±äÁ¿²¢²» "super"£¬ËüÃÇÐèÒªÓà 'global' ¹Ø¼ü×ÖÀ´Ê¹ËüÃÇÔÚº¯ÊýµÄ±¾µØÇøÓòÖÐÓÐЧ¡£ global $HTTP_POST_VARS; - + print $HTTP_POST_VARS['name']; - + // Superglobals ÔÚÈκη¶Î§ÄÚ¶¼ÓÐЧ£¬ËüÃDz¢²»ÐèÒª 'global' ÉùÃ÷¡£Superglobals ÊÇÔÚ PHP 4.1.0 ÒýÈëµÄ¡£ print $_POST['name']; } @@ -360,9 +360,9 @@ </programlisting> </informalexample> </para> - + <simpara> - + Another important feature of variable scoping is the <emphasis>static</emphasis> variable. A static variable exists only in a local function scope, but it does not lose its value @@ -491,7 +491,7 @@ A similar behaviour applies to the <literal>static</literal> statement. References are not stored statically: </simpara> - + <informalexample> <programlisting role="php"> <![CDATA[ @@ -560,9 +560,8 @@ <title>¿É±ä±äÁ¿</title> <simpara> - Sometimes it is convenient to be able to have variable variable - names. That is, a variable name which can be set and used - dynamically. A normal variable is set with a statement such as: + ÓÐʱºòʹÓÿɱä±äÁ¿ÃûÊǺܷ½±ãµÄ¡£¾ÍÊÇ˵£¬Ò»¸ö±äÁ¿µÄ±äÁ¿Ãû¿ÉÒÔ¶¯Ì¬µÄÉèÖúÍʹÓᣠ+ Ò»¸öÆÕͨµÄ±äÁ¿Í¨¹ýÉùÃ÷À´ÉèÖã¬ÀýÈ磺 </simpara> <informalexample> @@ -576,10 +575,9 @@ </informalexample> <simpara> - A variable variable takes the value of a variable and treats that - as the name of a variable. In the above example, - <emphasis>hello</emphasis>, can be used as the name of a variable - by using two dollar signs. i.e. + Ò»¸ö¿É±ä±äÁ¿»ñÈ¡ÁËÒ»¸öÆÕͨ±äÁ¿µÄÖµ×÷ΪÕâ¸ö¿É±ä±äÁ¿µÄ±äÁ¿Ãû¡£ + ÔÚÉÏÃæµÄÀý×ÓÖÐ <emphasis>hello</emphasis> ʹÓÃÁËÁ½¸öÃÀÔª·ûºÅ£¨$£©ÒÔºó£¬ + ¾Í¿ÉÒÔ×÷Ϊһ¸ö¿É±ä±äÁ¿µÄ±äÁ¿ÁË¡£ÀýÈ磺 </simpara> <informalexample> @@ -593,10 +591,8 @@ </informalexample> <simpara> - At this point two variables have been defined and stored in the - PHP symbol tree: <varname>$a</varname> with contents "hello" and - <varname>$hello</varname> with contents "world". Therefore, this - statement: + Õâʱ£¬Á½¸ö±äÁ¿¶¼±»¶¨ÒåÁË£º <varname>$a</varname> µÄÄÚÈÝÊÇ¡°hello¡± + ²¢ÇÒ <varname>$hello</varname> µÄÄÚÈÝÊÇ¡°world¡±¡£Òò´Ë£¬¿ÉÒÔ±íÊöΪ£º </simpara> <informalexample> @@ -610,7 +606,7 @@ </informalexample> <simpara> - produces the exact same output as: + ÒÔÏÂд·¨¸ü׼ȷ²¢ÇÒ»áÊä³öͬÑùµÄ½á¹û£º </simpara> <informalexample> @@ -624,7 +620,7 @@ </informalexample> <simpara> - i.e. they both produce: <computeroutput>hello world</computeroutput>. + ËüÃǶ¼»áÊä³ö£º <computeroutput>hello world</computeroutput> </simpara> <simpara> @@ -637,27 +633,27 @@ is: <varname>${$a[1]}</varname> for the first case and <varname>${$a}[1]</varname> for the second. </simpara> - + <simpara> - Please note that variable variables cannot be used with PHP's + Please note that variable variables cannot be used with PHP's <link linkend="language.variables.superglobals">Superglobal arrays</link>. - This means you cannot do things like <varname>${$_GET}</varname>. If you are + This means you cannot do things like <varname>${$_GET}</varname>. If you are looking for a way to handle availability of superglobals and the old - <varname>HTTP_*_VARS</varname>, you might want to try + <varname>HTTP_*_VARS</varname>, you might want to try <link linkend="language.references">referencing</link> them. </simpara> - + </sect1> <sect1 id="language.variables.external"> <title>PHP µÄÍⲿ±äÁ¿</title> - + <sect2 id="language.variables.external.form"> <title>HTML ±íµ¥ (GET ºÍ POST)</title> <simpara> - When a form is submitted to a PHP script, the information from - that form is automatically made available to the script. There + When a form is submitted to a PHP script, the information from + that form is automatically made available to the script. There are many ways to access this information, for example: </simpara> @@ -677,16 +673,16 @@ </para> <para> - Depending on your particular setup and personal preferences, there + Depending on your particular setup and personal preferences, there are many ways to access data from your HTML forms. Some examples are: </para> - + <para> <example> <title>´ÓÒ»¸ö¼òµ¥µÄ POST HTML ±íµ¥·ÃÎÊÊý¾Ý</title> <programlisting role="html"> <![CDATA[ -<?php +<?php // Available since PHP 4.1.0 print $_POST['username']; @@ -699,7 +695,7 @@ print $HTTP_POST_VARS['username']; -// Available if the PHP directive register_globals = on. As of +// Available if the PHP directive register_globals = on. As of // PHP 4.2.0 the default value of register_globals = off. // Using/relying on this method is not preferred. @@ -715,14 +711,14 @@ QUERY_STRING (the information after the '?' in an URL). So, for example, <literal>http://www.example.com/test.php?id=3</literal> contains GET data which is accessible with <varname>$_GET['id']</varname>. - See also <link linkend="reserved.variables.request">$_REQUEST</link> and + See also <link linkend="reserved.variables.request">$_REQUEST</link> and <function>import_request_variables</function>. </para> <note> <para> - <link linkend="language.variables.superglobals">Superglobal arrays</link>, - like <varname>$_POST</varname> and <varname>$_GET</varname>, became + <link linkend="language.variables.superglobals">Superglobal arrays</link>, + like <varname>$_POST</varname> and <varname>$_GET</varname>, became available in PHP 4.1.0 </para> </note> @@ -730,29 +726,29 @@ <para> As shown, before PHP 4.2.0 the default value for <link linkend="ini.register-globals">register_globals</link> - was <emphasis>on</emphasis>. And, in PHP 3 it was always on. The PHP - community is encouraging all to not rely on this directive - as it's preferred to assume it's <emphasis>off</emphasis> and code + was <emphasis>on</emphasis>. And, in PHP 3 it was always on. The PHP + community is encouraging all to not rely on this directive + as it's preferred to assume it's <emphasis>off</emphasis> and code accordingly. </para> <note> <para> - The <link linkend="ini.magic-quotes-gpc">magic_quotes_gpc</link> - configuration directive affects Get, Post and Cookie values. If + The <link linkend="ini.magic-quotes-gpc">magic_quotes_gpc</link> + configuration directive affects Get, Post and Cookie values. If turned on, value (It's "PHP!") will automagically become (It\'s \"PHP!\"). - Escaping is needed for DB insertion. See also - <function>addslashes</function>, <function>stripslashes</function> and + Escaping is needed for DB insertion. See also + <function>addslashes</function>, <function>stripslashes</function> and <link linkend="ini.magic-quotes-sybase">magic_quotes_sybase</link>. </para> </note> - + <simpara> - PHP also understands arrays in the context of form variables - (see the <link linkend="faq.html">related faq</link>). You may, - for example, group related variables together, or use this - feature to retrieve values from a multiple select input. For - example, let's post a form to itself and upon submission display + PHP also understands arrays in the context of form variables + (see the <link linkend="faq.html">related faq</link>). You may, + for example, group related variables together, or use this + feature to retrieve values from a multiple select input. For + example, let's post a form to itself and upon submission display the data: </simpara> @@ -836,16 +832,16 @@ the <function>setcookie</function> function. Cookies are part of the HTTP header, so the SetCookie function must be called before any output is sent to the browser. This is the same restriction - as for the <function>header</function> function. Cookie data - is then available in the appropriate cookie data arrays, such - as <varname>$_COOKIE</varname>, <varname>$HTTP_COOKIE_VARS</varname> - as well as in <varname>$_REQUEST</varname>. See the - <function>setcookie</function> manual page for more details and + as for the <function>header</function> function. Cookie data + is then available in the appropriate cookie data arrays, such + as <varname>$_COOKIE</varname>, <varname>$HTTP_COOKIE_VARS</varname> + as well as in <varname>$_REQUEST</varname>. See the + <function>setcookie</function> manual page for more details and examples. </simpara> <simpara> - If you wish to assign multiple values to a single cookie variable, you + If you wish to assign multiple values to a single cookie variable, you may assign it as an array. For example: </simpara> @@ -859,11 +855,11 @@ ]]> </programlisting> </informalexample> - + <simpara> - That will create two seperate cookies although MyCookie will now - be a single array in your script. If you want to set just one cookie - with multiple values, consider using <function>serialize</function> or + That will create two seperate cookies although MyCookie will now + be a single array in your script. If you want to set just one cookie + with multiple values, consider using <function>serialize</function> or <function>explode</function> on the value first. </simpara> @@ -930,15 +926,15 @@ <function>gettype</function>, <function>is_array</function>, <function>is_float</function>, <function>is_int</function>, <function>is_object</function>, and - <function>is_string</function>. See also the chapter on + <function>is_string</function>. See also the chapter on <link linkend="language.types">Types</link>. </para> </sect2> </sect1> - + </chapter> - + <!-- Keep this comment at the end of the file Local variables: mode: sgml
Index: phpdoc-zh/language/variables.xml diff -u phpdoc-zh/language/variables.xml:1.5 phpdoc-zh/language/variables.xml:1.6 --- phpdoc-zh/language/variables.xml:1.5 Sat Dec 28 03:47:09 2002 +++ phpdoc-zh/language/variables.xml Mon Feb 10 04:58:49 2003 @@ -1,11 +1,11 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.5 $ --> -<!-- $Author: gregory $ --> +<!-- $Revision: 1.6 $ --> +<!-- $Author: lm92 $ --> <!-- EN-Revision: 1.56 Maintainer: verdana Status: --> <!-- CREDITS: Gregory --> <chapter id="language.variables"> <title>±äÁ¿</title> - + <sect1 id="language.variables.basics"> <title>»ù´¡</title> @@ -16,7 +16,7 @@ <para> ±äÁ¿ÃûÓë PHP ÖÐÆäËüµÄ±êǩһÑù×ñÑÏàͬµÄ¹æÔò¡£Ò»¸öÓÐЧµÄ±äÁ¿ÃûÓÉ×Öĸ»òÕßÏ»®Ïß¿ªÍ·£¬ºóÃæ¸úÉÏÈÎÒâÊýÁ¿µÄ×Öĸ£¬Êý×Ö£¬»òÕßÏ»®Ïß¡£°´ÕÕÕý³£µÄÕýÔò±í´ïʽ£¬Ëü½«±»±íÊöΪ£º'[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*' </para> - + <note> <simpara> ×ÖĸΪ a-z£¬A-Z£¬ASCII ×Ö·û´Ó 127 µ½ 255 £¨0x7f-0xff£©¡£ @@ -25,7 +25,7 @@ <para> <informalexample> - <programlisting role="php"> + <programlisting role="php"> <![CDATA[ <?php $var = "Bob"; @@ -116,7 +116,7 @@ <sect1 id="language.variables.predefined"> <title>Ô¤¶¨Òå±äÁ¿</title> - + <simpara> PHP ÌṩÁË´óÁ¿µÄÔ¤¶¨Òå±äÁ¿¡£ÓÉÓÚÐí¶à±äÁ¿ÒÀÀµÓÚÔËÐеķþÎñÆ÷µÄ°æ±¾ºÍÉèÖ㬼°ÆäËüÒòËØ£¬ËùÒÔ²¢Ã»ÓÐÏêϸµÄ˵Ã÷Îĵµ¡£Ò»Ð©Ô¤¶¨Òå±äÁ¿ÔÚ PHP ÒÔ<link linkend="features.commandline">ÃüÁîÐÐ</link>ÐÎʽÔËÐÐʱ²¢²»ÉúЧ¡£ÓйØÕâЩ±äÁ¿µÄÏêϸÁÐ±í£¬Çë²ÎÔÄ¡°<link linkend="reserved.variables">±£ÁôµÄÔ¤¶¨Òå±äÁ¿</link>¡±Ò»Õ¡£ </simpara> @@ -125,12 +125,12 @@ <simpara> PHP 4.2.0 ÒÔ¼°ºóÐø°æ±¾ÖУ¬ PHP Ö¸Áî <link linkend="ini.register-globals">register_globals</link> µÄĬÈÏֵΪ - <emphasis>off</emphasis>. ÕâÊÇ PHP µÄÒ»¸öÖ÷Òª±ä»¯¡£Èà register_globals µÄֵΪ <emphasis>off</emphasis> ½«Ó°Ïìµ½Ô¤¶¨Òå±äÁ¿¼¯ÔÚÈ«¾Ö·¶Î§ÄÚµÄÓÐЧÐÔ¡£ÀýÈ磬ΪÁ˵õ½ <varname>DOCUMENT_ROOT</varname> µÄÖµ£¬Ä㽫±ØÐëʹÓà + <emphasis>off</emphasis>. ÕâÊÇ PHP µÄÒ»¸öÖ÷Òª±ä»¯¡£Èà register_globals µÄֵΪ <emphasis>off</emphasis> ½«Ó°Ïìµ½Ô¤¶¨Òå±äÁ¿¼¯ÔÚÈ«¾Ö·¶Î§ÄÚµÄÓÐЧÐÔ¡£ÀýÈ磬ΪÁ˵õ½ <varname>DOCUMENT_ROOT</varname> µÄÖµ£¬Ä㽫±ØÐëʹÓà <varname>$_SERVER['DOCUMENT_ROOT']</varname> ´úÌæ <varname>$DOCUMENT_ROOT</varname>£¬ÓÖÈ磬ʹÓà <varname>$_GET['id']</varname> À´´úÌæ <varname>$id</varname> ´Ó URL <literal>http://www.example.com/test.php?id=3</literal> ÖлñÈ¡ id Öµ£¬Òà»òʹÓà <varname>$_ENV['HOME']</varname> À´´úÌæ <varname>$HOME</varname> »ñÈ¡»·¾³±äÁ¿ HOME µÄÖµ¡£ </simpara> <simpara> - ¸ü¶àÏà¹ØÐÅÏ¢£¬ÇëÔĶÁÅäÖÃÏîÄ¿ <link linkend="ini.register-globals">register_globals</link>£¬Óйذ²È«ÐÔµÄÒ»Õ <link linkend="security.registerglobals">ʹÓà Register Globals</link>£¬ÒÔ¼° PHP <ulink url="&url.php.release4.1.0;">4.1.0</ulink> ºÍ + ¸ü¶àÏà¹ØÐÅÏ¢£¬ÇëÔĶÁÅäÖÃÏîÄ¿ <link linkend="ini.register-globals">register_globals</link>£¬Óйذ²È«ÐÔµÄÒ»Õ <link linkend="security.registerglobals">ʹÓà Register Globals</link>£¬ÒÔ¼° PHP <ulink url="&url.php.release4.1.0;">4.1.0</ulink> ºÍ <ulink url="&url.php.release4.2.0;">4.2.0</ulink> µÄ·¢ÐÐͨ¸æ. </simpara> <simpara> @@ -148,7 +148,7 @@ ³¬¼¶È«¾Ö±äÁ¿²»Äܱ»ÓÃ×÷<link linkend="language.variables.variable">±äÁ¿±äÁ¿</link>. </para> </note> - + <para> Èç¹ûijЩ <link linkend="ini.variables-order">variables_order</link> ÖеıäÁ¿Ã»ÓÐÉ趨£¬ËüÃǵĶÔÓ¦µÄ PHP Ô¤¶¨ÒåÊý×éÒ²Êǿյġ£ </para> @@ -168,7 +168,7 @@ <term><link linkend="reserved.variables.server">$_SERVER</link></term> <listitem> <simpara> - ±äÁ¿ÓÉ Web ·þÎñÆ÷É趨»òÕßÖ±½ÓÓ뵱ǰ½Å±¾µÄÖ´Ðл·¾³Ïà¹ØÁª¡£ÀàËÆÓÚ¾ÉÊý×é <varname>$HTTP_SERVER_VARS</varname> + ±äÁ¿ÓÉ Web ·þÎñÆ÷É趨»òÕßÖ±½ÓÓ뵱ǰ½Å±¾µÄÖ´Ðл·¾³Ïà¹ØÁª¡£ÀàËÆÓÚ¾ÉÊý×é <varname>$HTTP_SERVER_VARS</varname> Êý×飨ÒÀÈ»ÓÐЧ£¬µ«·´¶ÔʹÓã©¡£ </simpara> </listitem> @@ -177,7 +177,7 @@ <term><link linkend="reserved.variables.get">$_GET</link></term> <listitem> <simpara> - ¾ÓÉ HTTP GET ·½·¨Ìá½»ÖÁ½Å±¾µÄ±äÁ¿¡£ÀàËÆÓÚ¾ÉÊý×é <varname>$HTTP_GET_VARS</varname> + ¾ÓÉ HTTP GET ·½·¨Ìá½»ÖÁ½Å±¾µÄ±äÁ¿¡£ÀàËÆÓÚ¾ÉÊý×é <varname>$HTTP_GET_VARS</varname> Êý×飨ÒÀÈ»ÓÐЧ£¬µ«·´¶ÔʹÓã©¡£ </simpara> </listitem> @@ -186,7 +186,7 @@ <term><link linkend="reserved.variables.post">$_POST</link></term> <listitem> <simpara> - ¾ÓÉ HTTP POST ·½·¨Ìá½»ÖÁ½Å±¾µÄ±äÁ¿¡£ÀàËÆÓÚ¾ÉÊý×é <varname>$HTTP_POST_VARS</varname> + ¾ÓÉ HTTP POST ·½·¨Ìá½»ÖÁ½Å±¾µÄ±äÁ¿¡£ÀàËÆÓÚ¾ÉÊý×é <varname>$HTTP_POST_VARS</varname> Êý×飨ÒÀÈ»ÓÐЧ£¬µ«·´¶ÔʹÓã©¡£ </simpara> </listitem> @@ -195,7 +195,7 @@ <term><link linkend="reserved.variables.cookies">$_COOKIE</link></term> <listitem> <simpara> - ¾ÓÉ HTTP Cookies ·½·¨Ìá½»ÖÁ½Å±¾µÄ±äÁ¿¡£ÀàËÆÓÚ¾ÉÊý×é <varname>$HTTP_COOKIE_VARS</varname> + ¾ÓÉ HTTP Cookies ·½·¨Ìá½»ÖÁ½Å±¾µÄ±äÁ¿¡£ÀàËÆÓÚ¾ÉÊý×é <varname>$HTTP_COOKIE_VARS</varname> Êý×飨ÒÀÈ»ÓÐЧ£¬µ«·´¶ÔʹÓã©¡£ </simpara> </listitem> @@ -204,7 +204,7 @@ <term><link linkend="reserved.variables.files">$_FILES</link></term> <listitem> <simpara> - ¾ÓÉ HTTP POST ÎļþÉÏ´«¶øÌá½»ÖÁ½Å±¾µÄ±äÁ¿¡£ÀàËÆÓÚ¾ÉÊý×é <varname>$HTTP_POST_FILES</varname> + ¾ÓÉ HTTP POST ÎļþÉÏ´«¶øÌá½»ÖÁ½Å±¾µÄ±äÁ¿¡£ÀàËÆÓÚ¾ÉÊý×é <varname>$HTTP_POST_FILES</varname> Êý×飨ÒÀÈ»ÓÐЧ£¬µ«·´¶ÔʹÓã©¡£ÏêϸÐÅÏ¢Çë²ÎÔÄ <link linkend="features.file-upload.post-method">POST ·½·¨ÉÏ´«</link>¡£ </simpara> </listitem> @@ -213,7 +213,7 @@ <term><link linkend="reserved.variables.environment">$_ENV</link></term> <listitem> <simpara> - Ö´Ðл·¾³Ìá½»ÖÁ½Å±¾µÄ±äÁ¿¡£ÀàËÆÓÚ¾ÉÊý×é <varname>$HTTP_ENV_VARS</varname> + Ö´Ðл·¾³Ìá½»ÖÁ½Å±¾µÄ±äÁ¿¡£ÀàËÆÓÚ¾ÉÊý×é <varname>$HTTP_ENV_VARS</varname> Êý×飨ÒÀÈ»ÓÐЧ£¬µ«·´¶ÔʹÓã©¡£ </simpara> </listitem> @@ -223,14 +223,14 @@ <listitem> <simpara> ¾ÓÉÈκÎÓû§ÊäÈë»úÖÆÌá½»ÖÁ½Å±¾µÄ±äÁ¿£¬Òò´Ë¸ÃÊý×é²¢²»ÖµµÃÐÅÈΡ£ËùÓаüº¬ÔÚ¸ÃÊý×éÖеıäÁ¿µÄ´æÔÚÓë·ñ - ÒÔ¼°±äÁ¿µÄ˳Ðò¾ù°´ÕÕ &php.ini; ÖÐµÄ <link linkend="ini.variables-order">variables_order</link> + ÒÔ¼°±äÁ¿µÄ˳Ðò¾ù°´ÕÕ &php.ini; ÖÐµÄ <link linkend="ini.variables-order">variables_order</link> ÅäÖÃָʾÀ´¶¨Òå¡£¸ÃÊý×éûÓÐÖ±½ÓÄ£Äâ PHP 4.1.0 µÄÔçÆÚ°æ±¾¡£²ÎÕÕ <function>import_request_variables</function>¡£ </simpara> <note> <simpara> µ±ÔËÐÐÓÚ <link linkend="features.commandline">ÃüÁîÐÐ</link> ģʽʱ£¬Õâ¸öÊý×齫 <emphasis>²»»á</emphasis> °üº¬ <varname>argv</varname> ºÍ <varname>argc</varname> Èë¿Ú£»ËüÃÇÒѾ´æÔÚÓÚÊý×é <varname>$_SERVER</varname> ÖС£ </simpara> - </note> + </note> </listitem> </varlistentry> <varlistentry> @@ -265,17 +265,17 @@ <simpara> ÕâÀï±äÁ¿ <varname>$a</varname> ½«»áÔÚ°üº¬Îļþ <filename>b.inc</filename> ÖÐÉúЧ¡£µ«ÊÇ£¬ÔÚÓû§×Ô¶¨Ò庯ÊýÖУ¬Ò»¸ö¾Ö²¿º¯Êý·¶Î§½«±»ÒýÈë¡£ÈκÎÓÃÓÚº¯ÊýÄÚ²¿µÄ±äÁ¿°´È±Ê¡Çé¿ö½«±»ÏÞÖÆÔÚ¾Ö²¿º¯Êý·¶Î§ÄÚ¡£·¶Àý£º </simpara> - + <informalexample> - <programlisting role="php"> + <programlisting role="php"> <![CDATA[ <?php -$a = 1; /* global scope */ +$a = 1; /* global scope */ function Test() -{ - echo $a; /* reference to local scope variable */ -} +{ + echo $a; /* reference to local scope variable */ +} Test(); ?> @@ -299,7 +299,7 @@ global $a, $b; $b = $a + $b; -} +} Sum(); echo $b; @@ -326,7 +326,7 @@ function Sum() { $GLOBALS["b"] = $GLOBALS["a"] + $GLOBALS["b"]; -} +} Sum(); echo $b; @@ -340,7 +340,7 @@ linkend="language.variables.superglobals">superglobal</link> ±äÁ¿¡£ÒÔÏ·¶ÀýÏÔʾÁË superglobals µÄÓô¦£º </simpara> <para> - + <informalexample> <programlisting role="php"> <![CDATA[ @@ -349,9 +349,9 @@ { // ´ó¶àÊýµÄÔ¤¶¨Òå±äÁ¿²¢²» "super"£¬ËüÃÇÐèÒªÓà 'global' ¹Ø¼ü×ÖÀ´Ê¹ËüÃÇÔÚº¯ÊýµÄ±¾µØÇøÓòÖÐÓÐЧ¡£ global $HTTP_POST_VARS; - + print $HTTP_POST_VARS['name']; - + // Superglobals ÔÚÈκη¶Î§ÄÚ¶¼ÓÐЧ£¬ËüÃDz¢²»ÐèÒª 'global' ÉùÃ÷¡£Superglobals ÊÇÔÚ PHP 4.1.0 ÒýÈëµÄ¡£ print $_POST['name']; } @@ -360,9 +360,9 @@ </programlisting> </informalexample> </para> - + <simpara> - + Another important feature of variable scoping is the <emphasis>static</emphasis> variable. A static variable exists only in a local function scope, but it does not lose its value @@ -491,7 +491,7 @@ A similar behaviour applies to the <literal>static</literal> statement. References are not stored statically: </simpara> - + <informalexample> <programlisting role="php"> <![CDATA[ @@ -560,9 +560,8 @@ <title>¿É±ä±äÁ¿</title> <simpara> - Sometimes it is convenient to be able to have variable variable - names. That is, a variable name which can be set and used - dynamically. A normal variable is set with a statement such as: + ÓÐʱºòʹÓÿɱä±äÁ¿ÃûÊǺܷ½±ãµÄ¡£¾ÍÊÇ˵£¬Ò»¸ö±äÁ¿µÄ±äÁ¿Ãû¿ÉÒÔ¶¯Ì¬µÄÉèÖúÍʹÓᣠ+ Ò»¸öÆÕͨµÄ±äÁ¿Í¨¹ýÉùÃ÷À´ÉèÖã¬ÀýÈ磺 </simpara> <informalexample> @@ -576,10 +575,9 @@ </informalexample> <simpara> - A variable variable takes the value of a variable and treats that - as the name of a variable. In the above example, - <emphasis>hello</emphasis>, can be used as the name of a variable - by using two dollar signs. i.e. + Ò»¸ö¿É±ä±äÁ¿»ñÈ¡ÁËÒ»¸öÆÕͨ±äÁ¿µÄÖµ×÷ΪÕâ¸ö¿É±ä±äÁ¿µÄ±äÁ¿Ãû¡£ + ÔÚÉÏÃæµÄÀý×ÓÖÐ <emphasis>hello</emphasis> ʹÓÃÁËÁ½¸öÃÀÔª·ûºÅ£¨$£©ÒÔºó£¬ + ¾Í¿ÉÒÔ×÷Ϊһ¸ö¿É±ä±äÁ¿µÄ±äÁ¿ÁË¡£ÀýÈ磺 </simpara> <informalexample> @@ -593,10 +591,8 @@ </informalexample> <simpara> - At this point two variables have been defined and stored in the - PHP symbol tree: <varname>$a</varname> with contents "hello" and - <varname>$hello</varname> with contents "world". Therefore, this - statement: + Õâʱ£¬Á½¸ö±äÁ¿¶¼±»¶¨ÒåÁË£º <varname>$a</varname> µÄÄÚÈÝÊÇ¡°hello¡± + ²¢ÇÒ <varname>$hello</varname> µÄÄÚÈÝÊÇ¡°world¡±¡£Òò´Ë£¬¿ÉÒÔ±íÊöΪ£º </simpara> <informalexample> @@ -610,7 +606,7 @@ </informalexample> <simpara> - produces the exact same output as: + ÒÔÏÂд·¨¸ü׼ȷ²¢ÇÒ»áÊä³öͬÑùµÄ½á¹û£º </simpara> <informalexample> @@ -624,7 +620,7 @@ </informalexample> <simpara> - i.e. they both produce: <computeroutput>hello world</computeroutput>. + ËüÃǶ¼»áÊä³ö£º <computeroutput>hello world</computeroutput> </simpara> <simpara> @@ -637,27 +633,27 @@ is: <varname>${$a[1]}</varname> for the first case and <varname>${$a}[1]</varname> for the second. </simpara> - + <simpara> - Please note that variable variables cannot be used with PHP's + Please note that variable variables cannot be used with PHP's <link linkend="language.variables.superglobals">Superglobal arrays</link>. - This means you cannot do things like <varname>${$_GET}</varname>. If you are + This means you cannot do things like <varname>${$_GET}</varname>. If you are looking for a way to handle availability of superglobals and the old - <varname>HTTP_*_VARS</varname>, you might want to try + <varname>HTTP_*_VARS</varname>, you might want to try <link linkend="language.references">referencing</link> them. </simpara> - + </sect1> <sect1 id="language.variables.external"> <title>PHP µÄÍⲿ±äÁ¿</title> - + <sect2 id="language.variables.external.form"> <title>HTML ±íµ¥ (GET ºÍ POST)</title> <simpara> - When a form is submitted to a PHP script, the information from - that form is automatically made available to the script. There + When a form is submitted to a PHP script, the information from + that form is automatically made available to the script. There are many ways to access this information, for example: </simpara> @@ -677,16 +673,16 @@ </para> <para> - Depending on your particular setup and personal preferences, there + Depending on your particular setup and personal preferences, there are many ways to access data from your HTML forms. Some examples are: </para> - + <para> <example> <title>´ÓÒ»¸ö¼òµ¥µÄ POST HTML ±íµ¥·ÃÎÊÊý¾Ý</title> <programlisting role="html"> <![CDATA[ -<?php +<?php // Available since PHP 4.1.0 print $_POST['username']; @@ -699,7 +695,7 @@ print $HTTP_POST_VARS['username']; -// Available if the PHP directive register_globals = on. As of +// Available if the PHP directive register_globals = on. As of // PHP 4.2.0 the default value of register_globals = off. // Using/relying on this method is not preferred. @@ -715,14 +711,14 @@ QUERY_STRING (the information after the '?' in an URL). So, for example, <literal>http://www.example.com/test.php?id=3</literal> contains GET data which is accessible with <varname>$_GET['id']</varname>. - See also <link linkend="reserved.variables.request">$_REQUEST</link> and + See also <link linkend="reserved.variables.request">$_REQUEST</link> and <function>import_request_variables</function>. </para> <note> <para> - <link linkend="language.variables.superglobals">Superglobal arrays</link>, - like <varname>$_POST</varname> and <varname>$_GET</varname>, became + <link linkend="language.variables.superglobals">Superglobal arrays</link>, + like <varname>$_POST</varname> and <varname>$_GET</varname>, became available in PHP 4.1.0 </para> </note> @@ -730,29 +726,29 @@ <para> As shown, before PHP 4.2.0 the default value for <link linkend="ini.register-globals">register_globals</link> - was <emphasis>on</emphasis>. And, in PHP 3 it was always on. The PHP - community is encouraging all to not rely on this directive - as it's preferred to assume it's <emphasis>off</emphasis> and code + was <emphasis>on</emphasis>. And, in PHP 3 it was always on. The PHP + community is encouraging all to not rely on this directive + as it's preferred to assume it's <emphasis>off</emphasis> and code accordingly. </para> <note> <para> - The <link linkend="ini.magic-quotes-gpc">magic_quotes_gpc</link> - configuration directive affects Get, Post and Cookie values. If + The <link linkend="ini.magic-quotes-gpc">magic_quotes_gpc</link> + configuration directive affects Get, Post and Cookie values. If turned on, value (It's "PHP!") will automagically become (It\'s \"PHP!\"). - Escaping is needed for DB insertion. See also - <function>addslashes</function>, <function>stripslashes</function> and + Escaping is needed for DB insertion. See also + <function>addslashes</function>, <function>stripslashes</function> and <link linkend="ini.magic-quotes-sybase">magic_quotes_sybase</link>. </para> </note> - + <simpara> - PHP also understands arrays in the context of form variables - (see the <link linkend="faq.html">related faq</link>). You may, - for example, group related variables together, or use this - feature to retrieve values from a multiple select input. For - example, let's post a form to itself and upon submission display + PHP also understands arrays in the context of form variables + (see the <link linkend="faq.html">related faq</link>). You may, + for example, group related variables together, or use this + feature to retrieve values from a multiple select input. For + example, let's post a form to itself and upon submission display the data: </simpara> @@ -836,16 +832,16 @@ the <function>setcookie</function> function. Cookies are part of the HTTP header, so the SetCookie function must be called before any output is sent to the browser. This is the same restriction - as for the <function>header</function> function. Cookie data - is then available in the appropriate cookie data arrays, such - as <varname>$_COOKIE</varname>, <varname>$HTTP_COOKIE_VARS</varname> - as well as in <varname>$_REQUEST</varname>. See the - <function>setcookie</function> manual page for more details and + as for the <function>header</function> function. Cookie data + is then available in the appropriate cookie data arrays, such + as <varname>$_COOKIE</varname>, <varname>$HTTP_COOKIE_VARS</varname> + as well as in <varname>$_REQUEST</varname>. See the + <function>setcookie</function> manual page for more details and examples. </simpara> <simpara> - If you wish to assign multiple values to a single cookie variable, you + If you wish to assign multiple values to a single cookie variable, you may assign it as an array. For example: </simpara> @@ -859,11 +855,11 @@ ]]> </programlisting> </informalexample> - + <simpara> - That will create two seperate cookies although MyCookie will now - be a single array in your script. If you want to set just one cookie - with multiple values, consider using <function>serialize</function> or + That will create two seperate cookies although MyCookie will now + be a single array in your script. If you want to set just one cookie + with multiple values, consider using <function>serialize</function> or <function>explode</function> on the value first. </simpara> @@ -930,15 +926,15 @@ <function>gettype</function>, <function>is_array</function>, <function>is_float</function>, <function>is_int</function>, <function>is_object</function>, and - <function>is_string</function>. See also the chapter on + <function>is_string</function>. See also the chapter on <link linkend="language.types">Types</link>. </para> </sect2> </sect1> - + </chapter> - + <!-- Keep this comment at the end of the file Local variables: mode: sgml