cvs: phpdoc-zh /appendices migration.xml

From: Date: Tue, 06 Aug 2002 03:21:36 +0000
Subject: cvs: phpdoc-zh /appendices migration.xml
Groups: php.doc.zh 
Request: Send a blank email to doc-zh+get-255@lists.php.net to get a copy of this message
class007 Mon Aug 5 23:21:36 2002 EDT Modified files: /phpdoc-zh/appendices migration.xml Log: finished

Index: phpdoc-zh/appendices/migration.xml diff -u phpdoc-zh/appendices/migration.xml:1.3 phpdoc-zh/appendices/migration.xml:1.4 --- phpdoc-zh/appendices/migration.xml:1.3 Thu Aug 1 22:40:41 2002 +++ phpdoc-zh/appendices/migration.xml Mon Aug 5 23:21:36 2002 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="gb2312"?> -<!-- $Revision: 1.3 $ --> +<!-- $Revision: 1.4 $ --> <!-- $AUTHOR$ --> <!-- EN-Revision: 1.1 Maintainer: class007 Status: working --> <appendix id="migration"> @@ -29,16 +29,16 @@ <para> Ê×ÏÈÄúÓ¦¸Ã×¢Òâ PHP µÄ¿ªÊ¼/½áÊø±ê¼ÇÒѾ­¸Ä±ä¡£À쵀 <literal>&lt;? &gt;</literal> ÒѾ­±»ÈýÖÖеÄÐÎʽËùÌæ»»£º <example> - <title>Migration: old start/end tags</title> + <title>ÒÆÖ²£º¾ÉÓеĿªÊ¼/½áÊø±ê¼Ç</title> <programlisting role="php"> <![CDATA[ <? echo "This is PHP/FI 2.0 code.\n"; ?> ]]> </programlisting> </example> - As of version 2.0, PHP/FI also supports this variation: + PHP/FI 2.0 Ö§³ÖÕâÖֱ仯£º <example> - <title>Migration: first new start/end tags</title> + <title>ÒÆÖ²£ºµÚÒ»ÖÖ¿ªÊ¼/½áÊø±ê¼Ç</title> <programlisting role="php"> <![CDATA[ <? echo "This is PHP 3.0 code!\n"; ?> @@ -46,15 +46,9 @@ </programlisting> </example> - Notice that the end tag now consists of a question mark and a - greater-than character instead of just greater-than. However, if - you plan on using XML on your server, you will get problems with - the first new variant, because PHP may try to execute the XML - markup in XML documents as PHP code. Because of this, the - following variation was introduced: - + Çë×¢Ò⣬½áÊø±ê¼ÇÏÖÔÚÓÉÒ»¸öÎʺźÍÒ»¸ö´óÓÚºÅ×é³É¶ø²»½öÊÇÒ»¸ö´óÓں𣵫ÊÇ£¬ÄúÈç¹û¼Æ»®ÔÚÄúµÄ·þÎñÆ÷ÉÏʹÓà XML£¬Äú»á·¢ÏÖ´íÎó¡£ÕâÊÇÒòΪ PHP ¿ÉÄÜ»á°Ñ XML ÎĵµÖеıê¼Çµ±×÷ PHP ´úÂëÖ´ÐС£Òò´Ë£¬½¨ÒéʹÓÃÒÔÏ·½·¨£º <example> - <title>Migration: second new start/end tags</title> + <title>ÒÆÖ²£ºµÚ¶þÖÖ¿ªÊ¼/½áÊø±ê¼Ç</title> <programlisting role="php"> <![CDATA[ <?php echo "This is PHP 3.0 code!\n"; ?> @@ -62,13 +56,9 @@ </programlisting> </example> - Some people have had problems with editors that don't understand - the processing instruction tags at all. Microsoft FrontPage is one - such editor, and as a workaround for these, the following variation - was introduced as well: - + һЩ±à¼­Æ÷²¢²»ÄÜʶ±ð²¢´¦Àíָʾ±ê¼Ç£¬Microsoft FrontPage ¾ÍÊÇÆäÖÐÖ®Ò»¡£ÎªÁËʹ֮Õý³£¹¤×÷£¬Äú¿ÉÒÔʹÓÃÏÂÃæµÄ·½·¨£º <example> - <title>Migration: third new start/end tags</title> + <title>ÒÆÖ²£ºµÚÈýÖÖ¿ªÊ¼/½áÊø±ê¼Ç</title> <programlisting role="php"> <![CDATA[ <script language="php"> @@ -83,15 +73,12 @@ </section> <section id="migration.if-endif"> - <title>if..endif syntax</title> + <title>if..endif Óï·¨</title> <para> - The `alternative' way to write if/elseif/else statements, using if(); - elseif(); else; endif; cannot be efficiently implemented without - adding a large amount of complexity to the 3.0 parser. Because of - this, the syntax has been changed: + ʹÓà if(); elseif(); else; endif; ÕâһϵÁи´ÔÓµÄÓï¾äÎÞÖúÓÚ PHP 3.0 ½âÎöÆ÷µÄЧÂÊ¡£Òò´Ë£¬Óï·¨¸Ä±äΪ£º <example> - <title>Migration: old if..endif syntax</title> + <title>ÒÆÖ²£º¾ÉÓÐ if..endif Óï·¨</title> <programlisting role="php"> <![CDATA[ if ($foo); @@ -105,7 +92,7 @@ </programlisting> </example> <example> - <title>Migration: new if..endif syntax</title> + <title>ÒÆÖ²£ºÐ嵀 if..endif Óï·¨</title> <programlisting role="php"> <![CDATA[ if ($foo): @@ -119,18 +106,16 @@ </programlisting> </example> - Notice that the semicolons have been replaced by colons in all - statements but the one terminating the expression (endif). + ×¢Ò⣬ÔÚËùÓеÄÉùÃ÷Öзֺžù¸ÄΪðºÅ£¬³ýÁËĩβµÄ endif ÒÔÍâ¡£ </para> </section> <section id="migration-while"> - <title>while syntax</title> + <title>while Óï·¨</title> <para> - Just like with if..endif, the syntax of while..endwhile has changed - as well: + Èç if..endif Ò»Ñù£¬while..endwhile µÄÓï·¨Ò²½øÐÐÁ˸ı䣺 <example> - <title>Migration: old while..endwhile syntax</title> + <title>ÒÆÖ²£º¾ÉÓÐ while..endwhile Óï·¨</title> <programlisting role="php"> <![CDATA[ while ($more_to_come); @@ -140,7 +125,7 @@ </programlisting> </example> <example> - <title>Migration: new while..endwhile syntax</title> + <title>ÒÆÖ²£ºÐ嵀 new while..endwhile Óï·¨</title> <programlisting role="php"> <![CDATA[ while ($more_to_come): @@ -152,22 +137,18 @@ </para> <warning> <simpara> - If you use the old while..endwhile syntax in PHP 3.0, - you will get a never-ending loop. + Èç¹ûÄúÔÚ PHP 3.0 ÖÐʹÓÃ¾ÉµÄ while..endwhile Óï·¨£¬ÄúµÄ³ÌÐò»á½øÈëËÀÑ­»·. </simpara> </warning> </section> <section id="migration.expr"> - <title>Expression types</title> + <title>±í´ïʽÀàÐÍ</title> <simpara> - PHP/FI 2.0 used the left side of expressions to determine what type - the result should be. PHP 3.0 takes both sides into account when - determining result types, and this may cause 2.0 scripts to behave - unexpectedly in 3.0. + PHP/FI 2.0 ¸ù¾Ý±í´ïʽ×ó±ßÅжϱí´ïʽµÄÀàÐÍ£¬¶ø PHP 3.0 Ôò¸ù¾Ý±í´ïʽÁ½±ß½øÐÐÅжϡ£Õâ±ã¿ÉÄܵ¼Ö 2.0 ÏÂÔËÐÐÕý³£µÄ½Å±¾ÔÚ 3.0 ϵ¼ÖÂÒì³£¡£ </simpara> <para> - Consider this example: + ¿¼ÂÇÒ»ÏÂÀý×Ó£º <informalexample> <programlisting role="php"> <![CDATA[ @@ -183,20 +164,10 @@ </programlisting> </informalexample> - In PHP/FI 2.0, this would display both of $a's indices. In PHP - 3.0, it wouldn't display anything. The reason is that in PHP 2.0, - because the left argument's type was string, a string comparison - was made, and indeed <literal>""</literal> does not equal - <literal>"0"</literal>, and the loop went through. In PHP 3.0, - when a string is compared with an integer, an integer comparison is - made (the string is converted to an integer). This results in - comparing <literal>atoi("")</literal> which is - <literal>0</literal>, and <literal>variablelist</literal> which is - also <literal>0</literal>, and since <literal>0==0</literal>, the - loop doesn't go through even once. + ÔÚ PHP/FI 2.0 ÖУ¬Õâ¶Î³ÌÐò½«ÏÔʾËùÓÐ $a µÄË÷Òý£¬¶øÔÚ PHP 3.0 ÖУ¬Õâ¸ö³ÌÐòʲô¶¼²»»áÏÖʵ¡£Ô­ÒòÊÇ£¬ÔÚ PHP 2.0 ÖУ¬ÒòΪ×ó±ß²ÎÊýµÄÀàÐÍÊÇ string£¬ÓÚÊÇ£¬Ò»¸ö string µÄ¹ØÏµ±ã½¨Á¢ÆðÀ´¡£µ±È» <literal>""</literal> ²¢²»µÈÓÚ <literal>"0"</literal>£¬Ñ­»·´ÓÍ·µ½Î²¡£¶øÔÚ PHP 3.0 ÖУ¬µ±Ò»¸ö string ºÍÒ»¸ö integer ±È½Ïʱ£¬½« string ת»»Îª integer ²¢±È½Ï¡£½á¹ûÊDZȽÏֵΪ <literal>0</literal> µÄ <literal>atoi("")</literal>£¬ºÍͬÑùÊÇֵΪ <literal>0</literal> µÄ <literal>variablelist</literal>£¬Ò²¾ÍÊÇ <literal>0==0</literal>¡£ËùÒÔÑ­»·¸ù±¾Ã»ÓÐÖ´ÐС£ </para> <para> - The fix for this is simple. Replace the while statement with: + ºÜÈÝÒ×ÐÞÕýËü¡£°Ñ while ÉùÃ÷Ìæ»»Îª£º <informalexample> <programlisting role="php"> <![CDATA[ @@ -208,12 +179,9 @@ </section> <section id="migration.errors"> - <title>Error messages have changed</title> + <title>´íÎóÏûÏ¢ÒѾ­¸Ä±ä</title> <simpara> - PHP 3.0's error messages are usually more accurate than 2.0's were, - but you no longer get to see the code fragment causing the error. - You will be supplied with a file name and a line number for the - error, though. + PHP 3.0 µÄ´íÎóÏûϢͨ³£±È 2.0 µÄ¸ü¼Ó¾«È·£¬µ«ÊÇÄú²»»áÏñ 2.0 ÄÇÑùµÃµ½´íÎó´úÂëµÄƬ¶Ï¡£Äú»á»ñµÃÒ»¸öÎļþÃûºÍ´íÎóËùÔÚµÄÐкš£ </simpara> </section> @@ -224,30 +192,23 @@ in an expression like <literal>(1 || test_me())</literal>, the function <function>test_me</function> would not be executed since nothing can change the result of the expression after the - <literal>1</literal>. + <literal>1</literal>. </simpara> <simpara> This is a minor compatibility issue, but may cause unexpected - side-effects. + side-effects.(TODO) </simpara> </section> <section id="migration.truefalse"> - <title>Function &true;/&false; return values</title> + <title>º¯Êý &true;/&false; ·µ»ØÖµ</title> <simpara> - Most internal functions have been rewritten so they return &true; - when successful and &false; when failing, as opposed to 0 and -1 in - PHP/FI 2.0, respectively. The new behaviour allows for more - logical code, like <literal>$fp = fopen("/your/file") or - fail("darn!");</literal>. Because PHP/FI 2.0 had no clear rules - for what functions should return when they failed, most such - scripts will probably have to be checked manually after using the - 2.0 to 3.0 convertor. + ´óÁ¿µÄÄÚ²¿º¯Êý±»ÖØÐ´£¬Ê¹Ö®Ôڳɹ¦Ö´ÐÐʱ·µ»Ø &true;£¬¶øÔÚʧ°Üʱ·µ»Ø &false;¡£Õâ¾ÍÈçͬ PHP/FI 2.0 ·Ö±ð·µ»Ø 0 ºÍ -1 Ò»Ñù¡£ÕâÖָıäʹµÃ¸ü¶àµÄÂß¼­´úÂëµÃÒÔÖ´ÐУ¬±ÈÈç <literal>$fp = fopen("/your/file") or fail("darn!");</literal>¡£ÒòΪ PHP/FI 2.0 ¶Ôº¯ÊýÖ´ÐÐʧ°ÜµÄ·µ»ØÖµÃ»ÓÐÃ÷È·µÄ¹æ¶¨£¬ËùÒÔÔÚʹÓà 2.0 µ½ 3.0 ת»»Æ÷ʱ±ØÐëÊÖ¹¤¼ì²éº¯Êý·µ»ØÖµ´øÀ´µÄÓ°Ïì¡£ </simpara> <para> <example> - <title>Migration from 2.0: return values, old code</title> + <title>´Ó 2.0 ÒÆÖ²£º·µ»ØÖµ£¬¾ÉÓдúÂë</title> <programlisting role="php"> <![CDATA[ $fp = fopen($file, "r"); @@ -258,7 +219,7 @@ </programlisting> </example> <example> - <title>Migration from 2.0: return values, new code</title> + <title>´Ó 2.0 ÒÆÖ²£º·µ»ØÖµ£¬ÐµĴúÂë</title> <programlisting role="php"> <![CDATA[ $fp = @fopen($file, "r") or print("Could not open $file for reading<br>\n"); @@ -269,65 +230,49 @@ </section> <section id="migration-other"> - <title>Other incompatibilities</title> + <title>ÆäËü²»¼æÈÝ</title> <itemizedlist> <listitem><simpara> - The PHP 3.0 Apache module no longer supports Apache versions - prior to 1.2. Apache 1.2 or later is required. + PHP 3.0 µÄ Apache Ä£¿é²»ÔÙÖ§³Ö Apache 1.2 ÒÔǰµÄ°æ±¾¡£PHP 3.0 ÐèÒª Apache 1.2 »ò¸ü¸ß°æ±¾¡£ </simpara></listitem> <listitem><simpara> - <function>echo</function> no longer supports a format string. - Use the <function>printf</function> function instead. + <function>echo</function> ²»ÔÙÖ§³Ö¸ñʽ»¯×Ö·û´®¡£Èç¹ûÏë¸ñʽ»¯×Ö·û´®£¬Ê¹Óà <function>printf</function> º¯Êý¡£ </simpara></listitem> <listitem><simpara> - In PHP/FI 2.0, an implementation side-effect caused - <literal>$foo[0]</literal> to have the same effect as - <literal>$foo</literal>. This is not true for PHP 3.0. + ÔÚ PHP/FI 2.0 ÖУ¬<literal>$foo[0]</literal> ºÍ <literal>$foo</literal>ÓÐ×ÅͬÑùµÄЧ¹û¡£¶ø 3.0 Ôò²»ÊÇÕâÑùµÄ¡£ </simpara></listitem> <listitem> <simpara> - Reading arrays with <literal>$array[]</literal> is no longer - supported + ²»ÔÙÖ§³ÖʹÓà <literal>$array[]</literal> ¶ÁÈ¡Êý×é¡£ </simpara> <simpara> - That is, you cannot traverse an array by having a loop that does - <literal>$data = $array[]</literal>. Use <function>current</function> - and <function>next</function> instead. + Ò²¾ÍÊÇ˵£¬Äú²»¿ÉÒÔͨ¹ý×÷ <literal>$data = $array[]</literal> µÄÑ­»·À´±éÀúÒ»¸öÊý×顣ʹÓà <function>current</function> ºÍ <function>next</function> º¯ÊýÀ´´úÌæ¡£ </simpara> <simpara> - Also, <literal>$array1[] = $array2</literal> does not - append the values of <literal>$array2</literal> to - <literal>$array1</literal>, but appends - <literal>$array2</literal> as the last entry of - <literal>$array1</literal>. See also multidimensional array - support. + ͬÑùµÄ£¬<literal>$array1[] = $array2</literal> ²¢Ã»ÓÐ°Ñ <literal>$array2</literal> µÄÖµ¸³¸ø <literal>$array1</literal>£¬¶øÊÇ°Ñ <literal>$array2</literal> Õâ¸öÊý×鸳¸ø <literal>$array1</literal> µÄ×îºóÒ»Ïî¡£ÕâÖÖÇé¿öÒ²·¢ÉúÔÚ¶àάÊý×éÉÏ¡£ </simpara> </listitem> <listitem> <simpara> - <literal>"+"</literal> is no longer overloaded as a - concatenation operator for strings, instead it converts it's - arguments to numbers and performs numeric addition. Use - <literal>"."</literal> instead. + <literal>"+"</literal> ²»ÔÙÖØÔØÎª×Ö·û´®´®Á¬µÄÔËËã·û£¬ËüµÄ×÷ÓÃÊǰÑ×Ö·û´®×ª»»ÎªÊý×Ö²¢½«ËüÃÇÏà¼Ó¡£Èç¹ûÏë´®Á¬×Ö·û´®£¬Ê¹Óà <literal>"."</literal> ´úÌæ¡£ </simpara> </listitem> </itemizedlist> <example> - <title>Migration from 2.0: concatenation for strings</title> + <title>´Ó 2.0 ÒÆÖ²£º´®Á¬×Ö·û´®</title> <programlisting role="php"> <![CDATA[ echo "1" + "1"; ]]> </programlisting> <para> - In PHP 2.0 this would echo 11, in PHP 3.0 it would - echo 2. Instead use: + ÔÚ PHP 2.0 ÖиóÌÐò»áÏÔʾ 11£¬¶øÔÚ PHP 3.0 ÖлáÏÔʾ 2¡£Èç¹ûÒªÔÚ PHP 3.0 ÖдﵽͬÑùµÄЧ¹û£¬Ó¦¸ÃʹÓ㺠<programlisting role="php"> <![CDATA[ echo "1"."1"; @@ -342,7 +287,7 @@ </programlisting> </para> <para> - This would echo 2 in both PHP 2.0 and 3.0. + ÉÏÃæµÄ³ÌÐòÔÚ PHP 2.0 ºÍ 3.0 Öж¼»áÏÔʾ 2¡£ <programlisting role="php"> <![CDATA[ $a = 1; @@ -350,7 +295,7 @@ echo $a.$b; ]]> </programlisting> - This will echo 11 in PHP 3.0. + ÃæµÄ³ÌÐòÔÚ PHP 3.0 ÖлáÏÔʾ 11¡£ </para> </example> </section>
« previous php.doc.zh (#255) next »