cvs: phpdoc-zh /language references.xml

From: Date: Thu, 05 Sep 2002 18:30:42 +0000
Subject: cvs: phpdoc-zh /language references.xml
Groups: php.doc.zh 
Request: Send a blank email to doc-zh+get-470@lists.php.net to get a copy of this message
dallas Thu Sep 5 14:30:42 2002 EDT Modified files: /phpdoc-zh/language references.xml Log: Translation completed.

Index: phpdoc-zh/language/references.xml diff -u phpdoc-zh/language/references.xml:1.1 phpdoc-zh/language/references.xml:1.2 --- phpdoc-zh/language/references.xml:1.1 Thu Aug 29 18:12:53 2002 +++ phpdoc-zh/language/references.xml Thu Sep 5 14:30:42 2002 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="gb2312"?> -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> <!-- $Author: dallas $ --> <!-- EN-Revision: 1.24 Maintainer: dallas Status: ready --> <chapter id="language.references"> @@ -8,22 +8,17 @@ <sect1 id="language.references.whatare"> <title>ÒýÓÃÊÇʲô</title> <simpara> - References in PHP are a means to access the same variable content - by different names. They are not like C pointers, they are symbol - table aliases. Note that in PHP, variable name and variable content - are different, so the same content can have different names. - The most close analogy is with Unix filenames and files - - variable names are directory entries, while variable contents is - the file itself. References can be thought of as hardlinking in - Unix filesystem. + ÔÚ PHP ÖÐÒýÓÃÒâζ×ÅÓò»Í¬µÄÃû×Ö·ÃÎÊͬһ¸ö±äÁ¿ÄÚÈÝ¡£Õâ²¢²»Ïñ C µÄÖ¸Õ룬ËüÃÇÊÇ·ûºÅ±í±ðÃû¡£×¢ÒâÔÚ + PHP ÖУ¬±äÁ¿ÃûºÍ±äÁ¿ÄÚÈÝÊDz»Ò»ÑùµÄ£¬Òò´ËͬÑùµÄÄÚÈÝ¿ÉÒÔÓв»Í¬µÄÃû×Ö¡£×î½Ó½üµÄ±ÈÓ÷ÊÇ + Unix µÄÎļþÃûºÍÎļþ±¾Éí £­ ±äÁ¿ÃûÊÇĿ¼ÌõÄ¿£¬¶ø±äÁ¿ÄÚÈÝÔòÊÇÎļþ±¾Éí¡£ÒýÓÿÉÒÔ±»¿´×÷ÊÇ + Unix ÎļþϵͳÖеĽôÃÜÁ¬½Ó¡£ </simpara> </sect1> <sect1 id="language.references.whatdo"> <title>ÒýÓÃ×öʲô</title> <para> - PHP references allow you to make two variables to refer to the - same content. Meaning, when you do: + PHP µÄÒýÓÃÔÊÐíÄãÓÃÁ½¸ö±äÁ¿À´Ö¸Ïòͬһ¸öÄÚÈÝ¡£Òâ˼ÊÇ£¬µ±ÄãÕâÑù×öʱ£º <informalexample> <programlisting role="php"> <![CDATA[ @@ -31,21 +26,18 @@ ]]> </programlisting> </informalexample> - it means that <varname>$a</varname> and <varname>$b</varname> - point to the same variable. + ÕâÒâζ×Å <varname>$a</varname> ºÍ <varname>$b</varname> Ö¸ÏòÁËͬһ¸ö±äÁ¿¡£ <note> <para> - <varname>$a</varname> and <varname>$b</varname> are completely - equal here, that's not <varname>$a</varname> is pointing to - <varname>$b</varname> or vice versa, that's - <varname>$a</varname> and <varname>$b</varname> pointing to the - same place. + <varname>$a</varname> ºÍ <varname>$b</varname> ÔÚÕâÀïÊÇÍêÈ«ÏàͬµÄ£¬Õâ²¢²»ÊÇ + <varname>$a</varname> Ö¸ÏòÁË <varname>$b</varname> »òÕßÏà·´£¬¶øÊÇ + <varname>$a</varname> ºÍ <varname>$b</varname> Ö¸ÏòÁËͬһ¸öµØ·½¡£ </para> </note> </para> <para> - The same syntax can be used with functions, that return references, - and with <literal>new</literal> operator (in PHP 4.0.4 and later): + ͬÑùµÄÓï·¨¿ÉÒÔÓÃÔÚº¯ÊýÖУ¬Ëü·µ»ØÒýÓã¬ÒÔ¼°ÓÃÔÚ <literal>new</literal> + ÔËËã·ûÖУ¨PHP 4.0.4 ÒÔ¼°ÒÔºó°æ±¾£©£º <informalexample> <programlisting role="php"> <![CDATA[ @@ -57,26 +49,19 @@ </para> <note> <para> - Not using the <literal>&amp;</literal> operator causes a copy of the - object to be made. If you use <literal>$this</literal> in the class it - will operate on the current instance of the class. The assignment without - <literal>&amp;</literal> will copy the instance (i.e. the object) and - <literal>$this</literal> will operate on the copy, which is not always - what is desired. Usually you want to have a single instance to work with, - due to performance and memory consumption issues. + ²»Óà <literal>&amp;</literal> ÔËËã·ûµ¼Ö¶ÔÏóÉú³ÉÁËÒ»¸ö¿½±´¡£Èç¹ûÄãÔÚÀàÖÐÓà + <literal>$this</literal>£¬Ëü½«×÷ÓÃÓÚ¸ÃÀ൱ǰµÄʵÀý¡£Ã»ÓÐÓà <literal>&amp;</literal> + µÄ¸³Öµ½«¿½±´Õâ¸öʵÀý£¨ÀýÈç¶ÔÏ󣩲¢ÇÒ <literal>$this</literal> + ½«×÷ÓÃÓÚÕâ¸ö¿½±´ÉÏ£¬Õâ²¢²»×ÜÊÇÏëÒªµÄ½á¹û¡£ÓÉÓÚÐÔÄܺÍÄÚ´æÏûºÄµÄÎÊÌ⣬ͨ³£ÄãÖ»Ï빤×÷ÔÚÒ»¸öʵÀýÉÏÃæ¡£ </para> <para> - While you can use the <literal>@</literal> operator to - <emphasis>mute</emphasis> any errors in the constructor when using it as - <literal>@new</literal>, this does not work when using the - <literal>&amp;new</literal> statement. This is a limitation of the Zend - Engine and will therefore result in a parser error. + ¾¡¹ÜÄã¿ÉÒÔÓà <literal>@</literal> ÔËËã·ûÀ´<emphasis>¹Ø±Õ</emphasis>¹¹Ô캯ÊýÖеÄÈκδíÎóÐÅÏ¢£¬ÀýÈçÓà + <literal>@new</literal>£¬µ«Óà <literal>&amp;new</literal> Óï¾äʱÕâ²»ÆðЧ¹û¡£ÕâÊÇ + Zend ÒýÇæµÄÒ»¸öÏÞÖÆ²¢ÇһᵼÖÂÒ»¸ö½âÎö´íÎó¡£ </para> </note> <para> - The second thing references do is to pass variables - by-reference. This is done by making a local variable in a function and - a variable in the calling scope reference to the same content. Example: + ÒýÓÃ×öµÄµÚ¶þ¼þÊÂÊÇÓÃÒýÓô«µÝ±äÁ¿¡£ÕâÊÇͨ¹ýÔÚº¯ÊýÄÚ½¨Á¢Ò»¸ö±¾µØ±äÁ¿²¢ÇҸñäÁ¿ÔÚºô½Ð·¶Î§ÄÚÒýÓÃÁËͬһ¸öÄÚÈÝÀ´ÊµÏֵġ£ÀýÈ磺 <informalexample> <programlisting role="php"> <![CDATA[ @@ -90,23 +75,19 @@ ]]> </programlisting> </informalexample> - will make <varname>$a</varname> to be 6. This happens because in - the function <varname>foo</varname> the variable - <varname>$var</varname> refers to the same content as - <varname>$a</varname>. See also more detailed explanations about <link - linkend="language.references.pass">passing by reference</link>. + ½«Ê¹ <varname>$a</varname> ±ä³É 6¡£ÕâÊÇÒòΪÔÚ <varname>foo</varname> º¯ÊýÖбäÁ¿ + <varname>$var</varname> Ö¸ÏòÁËºÍ <varname>$a</varname> Ö¸ÏòµÄͬһ¸öÄÚÈÝ¡£¸ü¶àÏêϸ½âÊͼû<link + linkend="language.references.pass">ÒýÓô«µÝ</link>¡£ </para> <simpara> - The third thing reference can do is <link - linkend="language.references.return">return by reference</link>. + ÒýÓÃ×öµÄµÚÈý¼þÊÂÊÇ<link linkend="language.references.return">ÒýÓ÷µ»Ø</link>¡£ </simpara> </sect1> <sect1 id="language.references.arent"> <title>ÒýÓò»ÊÇʲô</title> <para> - As said before, references aren't pointers. That means, the - following construct won't do what you expect: + ÈçǰËùÊö£¬ÒýÓò»ÊÇÖ¸Õë¡£ÕâÒâζ×ÅÏÂÃæµÄ½á¹¹²»»á²úÉúÄãÔ¤ÆÚµÄЧ¹û£º <informalexample> <programlisting role="php"> <![CDATA[ @@ -120,24 +101,19 @@ </informalexample> </para> <simpara> - What happens is that <varname>$var</varname> in - <varname>foo</varname> will be bound with - <varname>$bar</varname> in caller, but then it will be - re-bound with <varname>$GLOBALS["baz"]</varname>. There's no way - to bind <varname>$bar</varname> in the calling scope to something else - using the reference mechanism, since <varname>$bar</varname> is not - available in the function <varname>foo</varname> (it is represented by - <varname>$var</varname>, but <varname>$var</varname> has only - variable contents and not name-to-value binding in the calling - symbol table). + Õ⽫ʹ <varname>foo</varname> º¯ÊýÖÐµÄ <varname>$var</varname> ±äÁ¿ÔÚº¯Êýµ÷ÓÃʱºÍ + <varname>$bar</varname> °ó¶¨ÔÚÒ»Æð£¬µ«½Ó×ÅÓÖ±»ÖØÐ°󶨵½ÁË + <varname>$GLOBALS["baz"]</varname> ÉÏÃæ¡£²»¿ÉÄÜͨ¹ýÒýÓûúÖÆ½« <varname>$bar</varname> + ÔÚº¯Êýµ÷Ó÷¶Î§Äڰ󶨵½±ðµÄ±äÁ¿ÉÏÃæ£¬ÒòΪÔÚº¯Êý <varname>foo</varname> Öв¢Ã»ÓбäÁ¿ + <varname>$bar</varname>£¨Ëü±»±íʾΪ <varname>$var</varname>£¬µ«ÊÇ <varname>$var</varname> + Ö»ÓбäÁ¿ÄÚÈݶøÃ»Óе÷Ó÷ûºÅ±íÖеÄÃû×Öµ½ÖµµÄ°ó¶¨£©¡£ </simpara> </sect1> <sect1 id="language.references.pass"> <title>ÒýÓô«µÝ</title> <para> - You can pass variable to function by reference, so that function could modify - its arguments. The syntax is as follows: + Äã¿ÉÒÔ½«Ò»¸ö±äÁ¿Í¨¹ýÒýÓô«µÝ¸øº¯Êý£¬ÕâÑù¸Ãº¯Êý¾Í¿ÉÒÔÐÞ¸ÄÆä²ÎÊýµÄÖµ¡£Óï·¨ÈçÏ£º <informalexample> <programlisting role="php"> <![CDATA[ @@ -152,26 +128,24 @@ ]]> </programlisting> </informalexample> - Note that there's no reference sign on function call - only on - function definition. Function definition alone is enough to - correctly pass the argument by reference. + ×¢ÒâÔÚº¯Êýµ÷ÓÃʱûÓÐÒýÓ÷ûºÅ £­ Ö»Óк¯Êý¶¨ÒåÖÐÓС£¹âÊǺ¯Êý¶¨Òå¾Í×㹻ʹ²ÎÊýͨ¹ýÒýÓÃÀ´ÕýÈ·´«µÝÁË¡£ </para> <para> - Following things can be passed by reference: + ÒÔÏÂÄÚÈÝ¿ÉÒÔͨ¹ýÒýÓô«µÝ£º <itemizedlist> <listitem> <simpara> - Variable, i.e. <literal>foo($a)</literal> + ±äÁ¿£¬ÀýÈç <literal>foo($a)</literal> </simpara> </listitem> <listitem> <simpara> - New statement, i.e. <literal>foo(new foobar())</literal> + New Óï¾ä£¬ÀýÈç <literal>foo(new foobar())</literal> </simpara> </listitem> <listitem> <para> - Reference, returned from a function, i.e.: + ´Óº¯ÊýÖзµ»ØµÄÒýÓã¬ÀýÈ磺 <informalexample> <programlisting role="php"> <![CDATA[ @@ -184,16 +158,13 @@ ]]> </programlisting> </informalexample> - See also explanations about <link - linkend="language.references.return">returning by reference</link>. + Ïêϸ½âÊͼû<link linkend="language.references.return">ÒýÓ÷µ»Ø</link>¡£ </para> </listitem> </itemizedlist> </para> <para> - Any other expression should not be passed by reference, as the - result is undefined. For example, the following examples of passing - by reference are invalid: + ÈÎºÎÆäËü±í´ïʽ¶¼²»ÄÜͨ¹ýÒýÓô«µÝ£¬½á¹û䶨Òå¡£ÀýÈçÏÂÃæÒýÓô«µÝµÄÀý×ÓÊÇÎÞЧµÄ£º <informalexample> <programlisting role="php"> <![CDATA[ @@ -209,16 +180,14 @@ ]]> </programlisting> </informalexample> - These requirements are for PHP 4.0.4 and later. + ÕâЩÌõ¼þÊÇ PHP 4.0.4 ÒÔ¼°ÒÔºó°æ±¾Óеġ£ </para> </sect1> <sect1 id="language.references.return"> <title>ÒýÓ÷µ»Ø</title> <para> - Returning by-reference is useful when you want to use a function - to find which variable a reference should be bound to. When - returning references, use this syntax: + ÒýÓ÷µ»ØÓÃÔÚµ±ÄãÏëÓú¯ÊýÕÒµ½ÒýÓÃÓ¦¸Ã±»°ó¶¨ÔÚÄÄÒ»¸ö±äÁ¿ÉÏÃæÊ±¡£µ±·µ»ØÒýÓÃʱ£¬Ê¹ÓôËÓï·¨£º <informalexample> <programlisting role="php"> <![CDATA[ @@ -233,17 +202,13 @@ ]]> </programlisting> </informalexample> - In this example, the property of the object returned by the - <varname>find_var</varname> function would be set, not the - copy, as it would be without using reference syntax. + ±¾ÀýÖÐ <varname>find_var</varname> º¯ÊýËù·µ»ØµÄ¶ÔÏóµÄÊôÐÔ½«±»É趨£¨ÒëÕߣºÖ¸µÄÊÇ $foo->x = 2; Óï¾ä£©£¬¶ø²»ÊÇ¿½±´£¬¾ÍºÍûÓÐÓÃÒýÓÃÓï·¨Ò»Ñù¡£ </para> <note> <simpara> - Unlike parameter passing, here you have to use - <literal>&amp;</literal> in both places - to indicate that you - return by-reference, not a copy as usual, and to indicate that - reference binding, rather than usual assignment, should be done - for <varname>$foo</varname>. + ºÍ²ÎÊý´«µÝ²»Í¬£¬ÕâÀï±ØÐëÔÚÁ½¸öµØ·½¶¼Óà <literal>&amp;</literal> ·ûºÅ £­ + À´Ö¸³ö·µ»ØµÄÊÇÒ»¸öÒýÓ㬶ø²»ÊÇͨ³£µÄÒ»¸ö¿½±´£¬Í¬ÑùÒ²Ö¸³ö <varname>$foo</varname> + ÊÇ×÷ΪÒýÓõİ󶨣¬¶ø²»ÊÇͨ³£µÄ¸³Öµ¡£ </simpara> </note> </sect1> @@ -251,9 +216,7 @@ <sect1 id="language.references.unset"> <title>È¡ÏûÒýÓÃ</title> <para> - When you unset the reference, you just break the binding between - variable name and variable content. This does not mean that - variable content will be destroyed. For example: + µ±Äã unset Ò»¸öÒýÓã¬Ö»ÊǶϿªÁ˱äÁ¿ÃûºÍ±äÁ¿ÄÚÈÝÖ®¼äµÄ°ó¶¨¡£Õâ²¢²»Òâζ×űäÁ¿ÄÚÈݱ»Ïú»ÙÁË¡£ÀýÈ磺 <informalexample> <programlisting role="php"> <![CDATA[ @@ -263,30 +226,23 @@ ]]> </programlisting> </informalexample> - won't unset <varname>$b</varname>, just <varname>$a</varname>. + ²»»á unset <varname>$b</varname>£¬Ö»ÊÇ <varname>$a</varname>¡£ </para> <simpara> - Again, it might be useful to think about this as analogous to Unix - <command>unlink</command> call. + ÔÙÄÃÕâ¸öºÍ Unix µÄ <command>unlink</command> µ÷ÓÃÀ´Àà±ÈһϿÉÄÜÓÐÖúÓÚÀí½â¡£ </simpara> </sect1> <sect1 id="language.references.spot"> <title>ÒýÓö¨Î»</title> <simpara> - Many syntax constructs in PHP are implemented via referencing - mechanisms, so everything told above about reference binding also - apply to these constructs. Some constructs, like passing and - returning by-reference, are mentioned above. Other constructs that - use references are: + Ðí¶à PHP µÄÓï·¨½á¹¹ÊÇͨ¹ýÒýÓûúÖÆÊµÏֵģ¬ËùÒÔÉÏÊöÓйØÒýÓð󶨵ÄÒ»ÇÐÒ²¶¼ÊÊÓÃÓÚÕâЩ½á¹¹¡£Ò»Ð©½á¹¹£¬ÀýÈçÒýÓô«µÝºÍ·µ»Ø£¬ÒѾ­ÔÚÉÏÃæÌáµ½ÁË¡£ÆäËüʹÓÃÒýÓõĽṹÓУº </simpara> <sect2 id="references.global"> - <title><literal>È«¾Ö</literal>ÒýÓÃ</title> + <title><literal>global</literal> ÒýÓÃ</title> <para> - When you declare variable as <command>global $var</command> you - are in fact creating reference to a global variable. That means, - this is the same as: + µ±Óà <command>global $var</command> ÉùÃ÷Ò»¸ö±äÁ¿Ê±Êµ¼ÊÉϽ¨Á¢ÁËÒ»¸öµ½È«¾Ö±äÁ¿µÄÒýÓá£Ò²¾ÍÊÇ˵ºÍÕâÑù×öÊÇÏàͬµÄ£º <informalexample> <programlisting role="php"> <![CDATA[ @@ -296,16 +252,14 @@ </informalexample> </para> <simpara> - That means, for example, that unsetting <varname>$var</varname> - won't unset global variable. + ÕâÒâζ×Å£¬ÀýÈ磬unset <varname>$var</varname> ²»»á unset È«¾Ö±äÁ¿¡£ </simpara> </sect2> <sect2 id="references.this"> <title><literal>$this</literal></title> <simpara> - In an object method, <varname>$this</varname> is always reference - to the caller object. + ÔÚÒ»¸ö¶ÔÏóµÄ·½·¨ÖУ¬<varname>$this</varname> ÓÀÔ¶Êǵ÷ÓÃËüµÄ¶ÔÏóµÄÒýÓᣠ</simpara> </sect2> </sect1>
« previous php.doc.zh (#470) next »