cvs: phpdoc-zh /appendices migration4.xml
| From: | Xiaoyu Huang | Date: | Thu, 08 Aug 2002 13:37:02 +0000 |
| Subject: | cvs: phpdoc-zh /appendices migration4.xml | ||
| Groups: | php.doc.zh | ||
| Request: | Send a blank email to doc-zh+get-286@lists.php.net to get a copy of this message | ||
class007 Thu Aug 8 09:37:02 2002 EDT
Modified files:
/phpdoc-zh/appendices migration4.xml
Log:
Íê³É
Index: phpdoc-zh/appendices/migration4.xml diff -u phpdoc-zh/appendices/migration4.xml:1.2 phpdoc-zh/appendices/migration4.xml:1.3 --- phpdoc-zh/appendices/migration4.xml:1.2 Wed Aug 7 21:52:40 2002 +++ phpdoc-zh/appendices/migration4.xml Thu Aug 8 09:37:01 2002 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="gb2312"?> -<!-- $Revision: 1.2 $ --> +<!-- $Revision: 1.3 $ --> <!-- $Author: class007 $ --> <!-- EN-Revision: 1.24 Maintainer: class007 Status: ready --> <appendix id="migration4"> @@ -183,192 +183,110 @@ Ðí¶àÒÑ´æÔÚµÄ PHP 3 ´úÂëʹÓõÄÓïÑÔÑùʽÔÚÏÖÔÚÓ¦µ±±»¿´×öÊǷdz£Ôã¸âµÄ¡£Òò´Ë£¬Èç¹ûÓà PHP 4 ±àÒë¸Ã½Å±¾£¬»á²úÉúºÜ¶à¶îÍâµÄ¾¯¸æÐÅÏ¢¡£Èç¹ûÄú²»Ïë¿´µ½ÕâЩÐÅÏ¢£¬Ö»Òª¼òµ¥µÄ°Ñ E_NOTICE Ñ¡Ïî¹Ø±Õ¡£µ«¸üºÃµÄ×ö·¨ÊÇÐÞÕý´úÂë¡£ </para> <para> - The most common case that will now produce notice messages is the - use of unquoted string constants as array indices. Both PHP 3 - and 4 will fall back to interpret these as strings if no - keyword or constant is known by that name, but whenever a - constant by that name had been defined anywhere else in the code - it might break your script. This can even become a security risk - if some intruder manages to redefine string constants in a way - that makes your script give him access rights he wasn't intended - to have. So PHP 4 will now warn you whenever you use unquoted - string constants as for example in - <literal>$_SERVER[REQUEST_METHOD]</literal>. Changing it - to <literal>$_SERVER['REQUEST_METHOD']</literal> will - make the parser happy and greatly improve the style and security - of your code. - </para> + ×î³£¼ûµÄ³öÏÖ notice ÌáʾÐÅÏ¢µÄÇé¿öÊÇÔÚÊý×éË÷ÒýÖÐʹÓÃûÓмÓÒýºÅµÄ×Ö·û´®¡£PHP 3 ºÍ PHP 4 ÔÚûÓÐͬÃûµÄ³£Á¿¶¨Òåʱ¶¼»á°ÑËü½âÊÍΪ×Ö·û´®£¬µ«ÊÇÎÞÂÛºÎʱֻҪÓг£Á¿ÊÇÒÔ¸Ã×Ö·û´®ÃüÃû£¬ÄúµÄ½Å±¾¾Í¿ÉÄÜ»á³öÏÖ´íÎó¡£Èç¹ûÓкڿÍÀûÓÃÕâÒ»µã£¬Éè·¨ÖØ¶¨Òå¸Ã³£Á¿£¬Õâ¸ö½Å±¾¾Í´æÔÚ°²È«Â©¶´¡£ËùÒÔÖ»Òª³öÏÖδ¼ÓÒýºÅµÄË÷Òý£¬PHP 4 ¾Í»á¾¯¸æÄú¶ÔËü¼ÓÒÔÐÞÕý¡£¾ÙÀýÀ´Ëµ£¬ÓЩ¶´µÄ´úÂë <literal>$_SERVER[REQUEST_METHOD]</literal>£¬Ö»Òª½«Ëü¸ÄΪ <literal>$_SERVER['REQUEST_METHOD']</literal>£¬´íÎóÌáʾ¾Í»áÏûʧ¡£ </para> <para> - Another thing PHP 4 will now tell you about is the use of - uninitialized variables or array elements. + PHP 4 »¹»á¶Ôδ³õʼ»¯µÄ±äÁ¿»òÊý×éÔªËØ¼ÓÒÔÌáʾ¡£ </para> </section> </section> <section id='migration4.initializers'> - <title>Initializers</title> + <title>³õʼ»¯</title> <para> - Static variable and class member initializers only accept scalar - values while in PHP 3 they accepted any valid expression. This - is, once again, due to the split between parsing and execution as - no code has yet been executed when the parser sees the - initializer. + PHP 4 Öо²Ì¬±äÁ¿ºÍÀà³ÉÔ±½ö½ÓÊܱêÁ¿Öµ£¬¶ø PHP 3 ÖнÓÊÜÈκÎÓÐЧµÄ±í´ïʽ¡£ÕâÊÇÓÉÓÚ½âÎöºÍÖ´ÐеķÖÀ룬µ¼ÖÂÖ»ÓÐÔÚ½âÎöÆ÷¿´µ½³õʼ»¯´úÂëºó²ÅÄÜÖ´ÐС£ </para> <para> - For classes you should use constructors to initialize member - variables instead. For static variables anything but a simple - static value rarely makes sense anyway. + ÄúÓ¦¸ÃʹÓù¹ÔìÆ÷À´³õʼ»¯Àà¡£¶Ô¾²Ì¬±äÁ¿£¬Ö»Óо²Ì¬µÄÖµ²ÅÓÐÒâÒå¡£ </para> </section> <section id='migration4.empty'> <title><literal>empty("0")</literal></title> <para> - The perhaps most controversial change in behavior has happened to the - behavior of the <function>empty</function>. A String containing - only the character '0' (zero) is now considered empty while it - wasn't in PHP 3. + ¿ÉÄÜ×î¾ßÕùÒéµÄ¸Ä±äÊÇ¶Ô <function>empty</function> º¯ÊýÐÐΪµÄ¸Ä±ä¡£Ò»¸ö½ö°üº¬×Ö·û¡°0¡±£¨ÊÇÁ㣬²»ÊÇÓ¢ÎÄ×Öĸ¡°O¡±£©µÄ×Ö·û´®ÏÖÔÚ±»ÈÏΪÊÇ¿Õ×Ö·û´®£¬¶ø PHP 3 ÖÐÔòÏà·´¡£ </para> <para> - This new behavior makes sense in web applications, with all input - fields returning strings even if numeric input is requested, and - with PHP's capabilities of automatic type conversion. But on the - other had it might break your code in a rather subtle way, - leading to misbehavior that is hard to track down if you do not - know about what to look for. + Õâ¸ö¸Ä±ä¶Ô web ³ÌÐòºÜÓÐÒâÒ壬ËùÓÐµÄ input ±íµ¥·µ»ØµÄ¶¼ÊÇ string£¬ÉõÖÁÌîдµÄÊÇÊý×Ö¡£PHP Äܹ»×Ô¶¯½øÐÐÀàÐÍת»»¡£µ«ÁíÒ»·½Ã棬Õâ¿ÉÄܲ»ÊÇÄú´úÂëµÄÔÒ⣬¿ÉÄܵ¼ÖÂÄú´úÂëĪÃûÆäÃîµÄ´íÎó¡£ </para> </section> <section id='migration4.missing'> - <title>Missing functions</title> + <title>ȱÉٵĺ¯Êý</title> <para> - While PHP 4 comes with a lot of new features, functions and - extensions, you may still find some functions from version 3 - missing. A small number of core functions has vanished because - they do not work with the new scheme of splitting parsing and - execution as introduced into 4 with the Zend engine. Other - functions and even complete extensions have become obsolete as - newer functions and extensions serve the same task better and/or - in a more general way. Some functions just simply haven't been - ported yet and finally some functions or extensions may be missing - due to license conflicts. + ËäÈ» PHP 4 ´øÀ´ÁËÐí¶àй¦ÄÜ¡¢º¯ÊýºÍÀ©Õ¹£¬Äú»¹ÊǻᷢÏÖһЩ±¾ÔÚ PHP 3 ÖдæÔڵĺ¯Êý²»¼ûÁË¡£ÉÙÁ¿µÄÄں˺¯Êý±»È¡Ïû£¬ÒòΪËüÃDz»·ûºÏ Zend engine еĽâÎö¡ª¡ªÖ´ÐеÄģʽ¡£ÁíÍâһЩº¯ÊýÉõÖÁÊÇÀ©Õ¹ÍêÈ«µÄ±»»Ä·Ï£¬ÊÇÒòΪеĺ¯Êý¿ÉÒÔ¸üºÃµÄÍê³É¾Éº¯ÊýµÄ¹¦ÄÜ¡£Ò»Ð©º¯ÊýÖ»Êǿպ¯Êý£¬¶øÁíһЩÒòΪ°æÈ¨³åÍ»¶øÈ¡ÏûÁË¡£ </para> <section id='migration4.missing.concept'> - <title>Functions missing due to conceptual changes</title> + <title>ÓÉÓÚ¸ÅÄîµÄ¸Ä±ä¶øÈ¡ÏûµÄº¯Êý</title> <para> - As PHP 4 now separates parsing from execution it is no longer - possible to change the behavior of the parser (now embedded in - the Zend engine) at runtime as parsing already happened by - then. So the function <function>short_tags</function> no longer - exists. You can still change the parsers behavior by setting - appropriate values in the &php.ini; file. + PHP 4 ÏÖÔÚ½«½âÎö´ÓÖ´ÐÐÖзÖÀ룬Òò´Ë²»¿ÉÄÜÔÚÔËÐÐʱ¼ä¸Ä±ä½âÎöÆ÷£¨ÏÖÔÚÒѾǶÈë Zend engine£©µÄÐÐΪ£¬´ËʱÒѾ½âÎöÍê±ÏÁË¡£ËùÒÔº¯Êý <function>short_tags</function> ²»ÔÙ´æÔÚ¡£ÄúÈÔÈ»¿ÉÒÔ¶Ô &php.ini; ÎļþÉèÖÃÊʵ±µÄÖµÒԸıä±àÒëÆ÷µÄÐÐΪ¡£ </para> <para> - Another feature of PHP 3 that is not a part of PHP 4 is the bundled - debugging interface. There are third-party add-ons for the Zend engine - which add similar functionality. - </para> + ÁíÒ»¸ö PHP 3 µÄ¹¦ÄÜÔÚ PHP 4 Öв»¸´´æÔÚ£ºÄÚ²¿À¦°óµÄ debug ½Ó¿Ú¡£ÏÖÔÚÓеÚÈý·½ Zend engine µÄ add-ons ÓÐ×ÅÀàËÆµÄ¹¦ÄÜ¡£ </para> </section> <section id='migration4.deprecate'> - <title>Deprecate functions and extensions</title> + <title>²»ÍƼöʹÓõĺ¯ÊýºÍÀ©Õ¹</title> <para> - The Adabas and Solid database extensions are no more. Long live - the unified ODBC extension instead. + Adabas and Solid Êý¾Ý¿âÀ©Õ¹²»ÔÙÍÆ¼öʹÓá£×îºÃʹÓÃͳһµÄ ODBC À©Õ¹´úÌæ¡£ </para> </section> <section id='migration4.unset'> - <title>Changed status for <function>unset</function></title> + <title><function>unset</function> µÄ¸Ä±ä</title> <para> - <function>unset</function>, although still available, is - implemented as a language construct rather than a function. + <function>unset</function>£¬ËäÈ»ÈÔÈ»¿ÉÒÔʹÓ㬵«ÊÇËü³ÉΪÁËÓïÑԽṹµÄÒ»²¿·Ö£¬¶ø²»ÊÇÒ»¸öº¯Êý¡£ </para> <para> - This does not have any consequences on the behavior of - <function>unset</function>, but testing for "unset" using - <function>function_exists</function> will return &false; as it would with - other language constructs that look like functions such as - <function>echo</function>. + Õâ¶Ô <function>unset</function> µÄÐÐΪ²»»á²úÉúʲôӰÏ죬µ«ÊÇʹÓà <function>function_exists</function> º¯Êý²âÊÔ¡°unset¡±Ê±»á·µ»Ø &false;¡£ËüÒѾÊÇ PHP ÓïÑÔµÄÒ»²¿·Ö£¬ËäÈ»ËüºÜÏñº¯Êý¡£ÕâºÍ <function>echo</function> ÊÇÒ»ÑùµÄ¡£ </para> <para> - Another more practical change is that it is no longer possible to - call <function>unset</function> indirectly, that is - <literal>$func="unset"; $func($somevar)</literal> won't work - anymore. + ÁíÒ»¸öʵ¼ÊµÄ¸Ä±äÊÇ£¬²»Äܼä½Óµ÷Óà <function>unset</function>¡£Òò´Ë <literal>$func="unset"; $func($somevar)</literal> ²»ÔÙ¹¤×÷¡£ </para> </section> </section> <section id='migration4.extensions'> - <title>PHP 3 extension</title> + <title>PHP 3 À©Õ¹</title> <para> - Extensions written for PHP 3 will not work with PHP 4, neither as binaries - nor at the source level. It is not difficult to port extensions to PHP 4 - if you have access to the original source. A detailed description of the - actual porting process is not part of this text. + Ϊ PHP 3 дµÄÀ©Õ¹ÔÚ PHP 4 Öв»ÔÙ¹¤×÷£¬¶þ½øÖÆ»òÔ´´úÂë¶¼²»ÐС£µ«Èç¹ûÄúÓÐÀ©Õ¹µÄÔʼ´úÂ룬½«Ëüת»»Îª PHP 4 µÄÀ©Õ¹ºÜÈÝÒס£ÕâÒѾ²»ÔÚ±¾ÎÄËùÌÖÂ۵ķ¶Î§ÖÐÁË¡£ </para> </section> <section id='migration4.strings'> - <title>Variable substitution in strings</title> + <title>×Ö·û´®ÖеıäÁ¿Ìæ»»</title> <para> - PHP 4 adds a new mechanism to variable substitution in - strings. You can now finally access object member variables and - elements from multidimensional arrays within strings. + PHP 4 Ìí¼ÓÁËÒ»¸öеĻúÖÆÒÔÌæ»»×Ö·û´®ÖеıäÁ¿¡£ÄúÏÖÔÚ¿ÉÒÔ·ÃÎÊ×Ö·û´®ÖеĶÔÏó³ÉÔ±±äÁ¿ºÍ¶àάÊý×éÔªËØ¡£ </para> <para> - To do so you have to enclose your variables with curly braces with - the dollar sign immediately following the opening brace: - <literal>{$...}</literal> + Èç¹ûÄúÏëÕâô×ö£¬ÄúÐèҪʹÓôóÀ¨ºÅ½«Ò»¸öÃÀÔª·ûºÅºÍ±äÁ¿ÃûÀ¨ÆðÀ´£¬¾ÍÏñÕâÑù£º<literal>{$...}</literal>¡£ </para> <para> - To embed the value of an object member variable into a string you - simply write <literal>"text {$obj->member} text"</literal> while - in PHP 3 you had to use something like <literal>"text - ".$obj->member." text"</literal>. + ÒªÔÚ×Ö·û´®ÖÐǶÈë¶ÔÏó³ÉÔ±±äÁ¿£¬Ö»Òª¼òµ¥µÄд <literal>"text {$obj->member} text"</literal>¡£¶øÔÚ PHP 3 ÖУ¬ÄúµÃʹÓà <literal>"text ".$obj->member." text"</literal>¡£ </para> <para> - This should lead to more readable code, while it may break - existing scripts written for PHP 3. But you can easily check for - this kind of problem by checking for the character combination - <literal>{$</literal> in your code and by replacing it with - <literal>\{$</literal> with your favorite search-and-replace - tool. + Õâ¸ö¸Ä½ø¿ÉÒÔʹ´úÂë¸üÒ×¶Á£¬µ«Õâ¿ÉÄÜ»áÆÆ»µÓà PHP 3 дµÄ´úÂë¡£µ«ÊÇÄúºÜÈÝÒ×ÐÞÕýËü£ºÔÚ´úÂëÖвéÕÒ×Ö·û´®ÖÐµÄ <literal>{$</literal>£¬Ê¹ÓÃËÑË÷Ìæ»»¹¤¾ß½«ËüÌæ»»Îª <literal>\{$</literal>¡£ </para> </section> <section id='migration4.cookies'> <title>Cookies</title> <para> - PHP 3 had the bad habit of setting cookies in the reverse order - of the <function>setcookie</function> calls in your code. PHP 4 - breaks with this habit and creates the cookie header lines in - exactly the same order as you set the cookies in the code. + PHP 3 ÔÚÉèÖà cookies ʱÓÐÒ»¸ö²»ºÃµÄϰ¹ß£¬Ëü×ÜÊǽ« <function>setcookie</function> ËùÉèÖÃµÄ cookies ÒÔÏà·´µÄ˳Ðò±£´æ¡£PHP 4 ¸Ä±äÁËÕâ¸öϰ¹ß£¬´´½¨ cookies ʱÒÔÄúµÄ´úÂëÖÐÉèÖà cookies µÄ˳Ðò±£´æ¡£ </para> <para> - This might break some existing code, but the old behaviour was so - strange to understand that it deserved a change to prevent further - problems in the future. + Õâ¿ÉÄÜʹµÃÔÓдúÂë²»ÄÜÕý³£¹¤×÷¡£µ«ÊÇ PHP 3 µÄÐÐΪµÄÈ·ºÜ¹Å¹Ö£¬Ó¦¸Ã¼ÓÒԸıäÒÔ·ÀÖ¹½«À´²úÉú¸ü¶àµÄÎÊÌâ¡£ </para> </section> <section id='migration4.variables'> - <title>Handling of global variables</title> + <title>´¦ÀíÈ«¾Ö±äÁ¿</title> <para> - While handling of global variables had the focus on to be easy in - PHP 3 and early versions of PHP 4, the focus has changed to be more - secure. While in PHP 3 the following example worked fine, in PHP 4 it - has to be unset($GLOBALS["id"]);. This is only one issue of global - variable handling. You should always have used $GLOBALS, with - newer versions of PHP 4 you are forced to do so in most cases. - Read more on this subject in the <link linkend="references.global"> - <literal>global</literal> references section</link>. + ÔÚ PHP 3 ºÍ PHP 4 ÔçЩ°æ±¾Öд¦ÀíÈ«¾Ö±äÁ¿µÄÖØÐÄ·ÅÔÚÁËÒ×ÓÃÉÏ£¬¶øÏÖÔÚ£¬½¹µã·Åµ½ÁËÈçºÎ¸ü°²È«µÄ´¦ÀíËüÃÇÉÏ¡£ÔÚ PHP 3 ÖÐÏÂÃæµÄ´úÂ빤×÷Õý³££¬µ«ÊÇ PHP 4 ÖоÍҪʹÓà unset($GLOBALS["id"]);¡£Õâ½ö½öÊÇÈ«¾Ö±äÁ¿´¦ÀíµÄÒ»¸öÎÊÌâ¡£ÄúÓ¦µ±×ÜÊÇʹÓà $GLOBALS£¬ÔÚ¸üа汾µÄ PHP 4 ÖÐÄúÓ¦¸ÃÇ¿ÆÈ×Ô¼ºÔڴ󲿷ÖÇé¿öÖÐʹÓÃËü¡£¸ü¶àÐÅÏ¢Çë²Î¿¼ <link linkend="references.global"> <literal>global</literal> ²Î¿¼Õ½Ú</link>. </para> <example> - <title>Migration of global variables</title> + <title>È«¾Ö±äÁ¿µÄÒÆÖ²</title> <programlisting role="php"> <![CDATA[ <?php @@ -379,7 +297,7 @@ unset($id); } test(); -echo($id); // This will print out 1 in PHP 4 +echo($id); // ÔÚ PHP 4 ÖÐÕâÀï»á´òÓ¡³ö 1 ?> ]]> </programlisting>
Index: phpdoc-zh/appendices/migration4.xml diff -u phpdoc-zh/appendices/migration4.xml:1.2 phpdoc-zh/appendices/migration4.xml:1.3 --- phpdoc-zh/appendices/migration4.xml:1.2 Wed Aug 7 21:52:40 2002 +++ phpdoc-zh/appendices/migration4.xml Thu Aug 8 09:37:01 2002 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="gb2312"?> -<!-- $Revision: 1.2 $ --> +<!-- $Revision: 1.3 $ --> <!-- $Author: class007 $ --> <!-- EN-Revision: 1.24 Maintainer: class007 Status: ready --> <appendix id="migration4"> @@ -183,192 +183,110 @@ Ðí¶àÒÑ´æÔÚµÄ PHP 3 ´úÂëʹÓõÄÓïÑÔÑùʽÔÚÏÖÔÚÓ¦µ±±»¿´×öÊǷdz£Ôã¸âµÄ¡£Òò´Ë£¬Èç¹ûÓà PHP 4 ±àÒë¸Ã½Å±¾£¬»á²úÉúºÜ¶à¶îÍâµÄ¾¯¸æÐÅÏ¢¡£Èç¹ûÄú²»Ïë¿´µ½ÕâЩÐÅÏ¢£¬Ö»Òª¼òµ¥µÄ°Ñ E_NOTICE Ñ¡Ïî¹Ø±Õ¡£µ«¸üºÃµÄ×ö·¨ÊÇÐÞÕý´úÂë¡£ </para> <para> - The most common case that will now produce notice messages is the - use of unquoted string constants as array indices. Both PHP 3 - and 4 will fall back to interpret these as strings if no - keyword or constant is known by that name, but whenever a - constant by that name had been defined anywhere else in the code - it might break your script. This can even become a security risk - if some intruder manages to redefine string constants in a way - that makes your script give him access rights he wasn't intended - to have. So PHP 4 will now warn you whenever you use unquoted - string constants as for example in - <literal>$_SERVER[REQUEST_METHOD]</literal>. Changing it - to <literal>$_SERVER['REQUEST_METHOD']</literal> will - make the parser happy and greatly improve the style and security - of your code. - </para> + ×î³£¼ûµÄ³öÏÖ notice ÌáʾÐÅÏ¢µÄÇé¿öÊÇÔÚÊý×éË÷ÒýÖÐʹÓÃûÓмÓÒýºÅµÄ×Ö·û´®¡£PHP 3 ºÍ PHP 4 ÔÚûÓÐͬÃûµÄ³£Á¿¶¨Òåʱ¶¼»á°ÑËü½âÊÍΪ×Ö·û´®£¬µ«ÊÇÎÞÂÛºÎʱֻҪÓг£Á¿ÊÇÒÔ¸Ã×Ö·û´®ÃüÃû£¬ÄúµÄ½Å±¾¾Í¿ÉÄÜ»á³öÏÖ´íÎó¡£Èç¹ûÓкڿÍÀûÓÃÕâÒ»µã£¬Éè·¨ÖØ¶¨Òå¸Ã³£Á¿£¬Õâ¸ö½Å±¾¾Í´æÔÚ°²È«Â©¶´¡£ËùÒÔÖ»Òª³öÏÖδ¼ÓÒýºÅµÄË÷Òý£¬PHP 4 ¾Í»á¾¯¸æÄú¶ÔËü¼ÓÒÔÐÞÕý¡£¾ÙÀýÀ´Ëµ£¬ÓЩ¶´µÄ´úÂë <literal>$_SERVER[REQUEST_METHOD]</literal>£¬Ö»Òª½«Ëü¸ÄΪ <literal>$_SERVER['REQUEST_METHOD']</literal>£¬´íÎóÌáʾ¾Í»áÏûʧ¡£ </para> <para> - Another thing PHP 4 will now tell you about is the use of - uninitialized variables or array elements. + PHP 4 »¹»á¶Ôδ³õʼ»¯µÄ±äÁ¿»òÊý×éÔªËØ¼ÓÒÔÌáʾ¡£ </para> </section> </section> <section id='migration4.initializers'> - <title>Initializers</title> + <title>³õʼ»¯</title> <para> - Static variable and class member initializers only accept scalar - values while in PHP 3 they accepted any valid expression. This - is, once again, due to the split between parsing and execution as - no code has yet been executed when the parser sees the - initializer. + PHP 4 Öо²Ì¬±äÁ¿ºÍÀà³ÉÔ±½ö½ÓÊܱêÁ¿Öµ£¬¶ø PHP 3 ÖнÓÊÜÈκÎÓÐЧµÄ±í´ïʽ¡£ÕâÊÇÓÉÓÚ½âÎöºÍÖ´ÐеķÖÀ룬µ¼ÖÂÖ»ÓÐÔÚ½âÎöÆ÷¿´µ½³õʼ»¯´úÂëºó²ÅÄÜÖ´ÐС£ </para> <para> - For classes you should use constructors to initialize member - variables instead. For static variables anything but a simple - static value rarely makes sense anyway. + ÄúÓ¦¸ÃʹÓù¹ÔìÆ÷À´³õʼ»¯Àà¡£¶Ô¾²Ì¬±äÁ¿£¬Ö»Óо²Ì¬µÄÖµ²ÅÓÐÒâÒå¡£ </para> </section> <section id='migration4.empty'> <title><literal>empty("0")</literal></title> <para> - The perhaps most controversial change in behavior has happened to the - behavior of the <function>empty</function>. A String containing - only the character '0' (zero) is now considered empty while it - wasn't in PHP 3. + ¿ÉÄÜ×î¾ßÕùÒéµÄ¸Ä±äÊÇ¶Ô <function>empty</function> º¯ÊýÐÐΪµÄ¸Ä±ä¡£Ò»¸ö½ö°üº¬×Ö·û¡°0¡±£¨ÊÇÁ㣬²»ÊÇÓ¢ÎÄ×Öĸ¡°O¡±£©µÄ×Ö·û´®ÏÖÔÚ±»ÈÏΪÊÇ¿Õ×Ö·û´®£¬¶ø PHP 3 ÖÐÔòÏà·´¡£ </para> <para> - This new behavior makes sense in web applications, with all input - fields returning strings even if numeric input is requested, and - with PHP's capabilities of automatic type conversion. But on the - other had it might break your code in a rather subtle way, - leading to misbehavior that is hard to track down if you do not - know about what to look for. + Õâ¸ö¸Ä±ä¶Ô web ³ÌÐòºÜÓÐÒâÒ壬ËùÓÐµÄ input ±íµ¥·µ»ØµÄ¶¼ÊÇ string£¬ÉõÖÁÌîдµÄÊÇÊý×Ö¡£PHP Äܹ»×Ô¶¯½øÐÐÀàÐÍת»»¡£µ«ÁíÒ»·½Ã棬Õâ¿ÉÄܲ»ÊÇÄú´úÂëµÄÔÒ⣬¿ÉÄܵ¼ÖÂÄú´úÂëĪÃûÆäÃîµÄ´íÎó¡£ </para> </section> <section id='migration4.missing'> - <title>Missing functions</title> + <title>ȱÉٵĺ¯Êý</title> <para> - While PHP 4 comes with a lot of new features, functions and - extensions, you may still find some functions from version 3 - missing. A small number of core functions has vanished because - they do not work with the new scheme of splitting parsing and - execution as introduced into 4 with the Zend engine. Other - functions and even complete extensions have become obsolete as - newer functions and extensions serve the same task better and/or - in a more general way. Some functions just simply haven't been - ported yet and finally some functions or extensions may be missing - due to license conflicts. + ËäÈ» PHP 4 ´øÀ´ÁËÐí¶àй¦ÄÜ¡¢º¯ÊýºÍÀ©Õ¹£¬Äú»¹ÊǻᷢÏÖһЩ±¾ÔÚ PHP 3 ÖдæÔڵĺ¯Êý²»¼ûÁË¡£ÉÙÁ¿µÄÄں˺¯Êý±»È¡Ïû£¬ÒòΪËüÃDz»·ûºÏ Zend engine еĽâÎö¡ª¡ªÖ´ÐеÄģʽ¡£ÁíÍâһЩº¯ÊýÉõÖÁÊÇÀ©Õ¹ÍêÈ«µÄ±»»Ä·Ï£¬ÊÇÒòΪеĺ¯Êý¿ÉÒÔ¸üºÃµÄÍê³É¾Éº¯ÊýµÄ¹¦ÄÜ¡£Ò»Ð©º¯ÊýÖ»Êǿպ¯Êý£¬¶øÁíһЩÒòΪ°æÈ¨³åÍ»¶øÈ¡ÏûÁË¡£ </para> <section id='migration4.missing.concept'> - <title>Functions missing due to conceptual changes</title> + <title>ÓÉÓÚ¸ÅÄîµÄ¸Ä±ä¶øÈ¡ÏûµÄº¯Êý</title> <para> - As PHP 4 now separates parsing from execution it is no longer - possible to change the behavior of the parser (now embedded in - the Zend engine) at runtime as parsing already happened by - then. So the function <function>short_tags</function> no longer - exists. You can still change the parsers behavior by setting - appropriate values in the &php.ini; file. + PHP 4 ÏÖÔÚ½«½âÎö´ÓÖ´ÐÐÖзÖÀ룬Òò´Ë²»¿ÉÄÜÔÚÔËÐÐʱ¼ä¸Ä±ä½âÎöÆ÷£¨ÏÖÔÚÒѾǶÈë Zend engine£©µÄÐÐΪ£¬´ËʱÒѾ½âÎöÍê±ÏÁË¡£ËùÒÔº¯Êý <function>short_tags</function> ²»ÔÙ´æÔÚ¡£ÄúÈÔÈ»¿ÉÒÔ¶Ô &php.ini; ÎļþÉèÖÃÊʵ±µÄÖµÒԸıä±àÒëÆ÷µÄÐÐΪ¡£ </para> <para> - Another feature of PHP 3 that is not a part of PHP 4 is the bundled - debugging interface. There are third-party add-ons for the Zend engine - which add similar functionality. - </para> + ÁíÒ»¸ö PHP 3 µÄ¹¦ÄÜÔÚ PHP 4 Öв»¸´´æÔÚ£ºÄÚ²¿À¦°óµÄ debug ½Ó¿Ú¡£ÏÖÔÚÓеÚÈý·½ Zend engine µÄ add-ons ÓÐ×ÅÀàËÆµÄ¹¦ÄÜ¡£ </para> </section> <section id='migration4.deprecate'> - <title>Deprecate functions and extensions</title> + <title>²»ÍƼöʹÓõĺ¯ÊýºÍÀ©Õ¹</title> <para> - The Adabas and Solid database extensions are no more. Long live - the unified ODBC extension instead. + Adabas and Solid Êý¾Ý¿âÀ©Õ¹²»ÔÙÍÆ¼öʹÓá£×îºÃʹÓÃͳһµÄ ODBC À©Õ¹´úÌæ¡£ </para> </section> <section id='migration4.unset'> - <title>Changed status for <function>unset</function></title> + <title><function>unset</function> µÄ¸Ä±ä</title> <para> - <function>unset</function>, although still available, is - implemented as a language construct rather than a function. + <function>unset</function>£¬ËäÈ»ÈÔÈ»¿ÉÒÔʹÓ㬵«ÊÇËü³ÉΪÁËÓïÑԽṹµÄÒ»²¿·Ö£¬¶ø²»ÊÇÒ»¸öº¯Êý¡£ </para> <para> - This does not have any consequences on the behavior of - <function>unset</function>, but testing for "unset" using - <function>function_exists</function> will return &false; as it would with - other language constructs that look like functions such as - <function>echo</function>. + Õâ¶Ô <function>unset</function> µÄÐÐΪ²»»á²úÉúʲôӰÏ죬µ«ÊÇʹÓà <function>function_exists</function> º¯Êý²âÊÔ¡°unset¡±Ê±»á·µ»Ø &false;¡£ËüÒѾÊÇ PHP ÓïÑÔµÄÒ»²¿·Ö£¬ËäÈ»ËüºÜÏñº¯Êý¡£ÕâºÍ <function>echo</function> ÊÇÒ»ÑùµÄ¡£ </para> <para> - Another more practical change is that it is no longer possible to - call <function>unset</function> indirectly, that is - <literal>$func="unset"; $func($somevar)</literal> won't work - anymore. + ÁíÒ»¸öʵ¼ÊµÄ¸Ä±äÊÇ£¬²»Äܼä½Óµ÷Óà <function>unset</function>¡£Òò´Ë <literal>$func="unset"; $func($somevar)</literal> ²»ÔÙ¹¤×÷¡£ </para> </section> </section> <section id='migration4.extensions'> - <title>PHP 3 extension</title> + <title>PHP 3 À©Õ¹</title> <para> - Extensions written for PHP 3 will not work with PHP 4, neither as binaries - nor at the source level. It is not difficult to port extensions to PHP 4 - if you have access to the original source. A detailed description of the - actual porting process is not part of this text. + Ϊ PHP 3 дµÄÀ©Õ¹ÔÚ PHP 4 Öв»ÔÙ¹¤×÷£¬¶þ½øÖÆ»òÔ´´úÂë¶¼²»ÐС£µ«Èç¹ûÄúÓÐÀ©Õ¹µÄÔʼ´úÂ룬½«Ëüת»»Îª PHP 4 µÄÀ©Õ¹ºÜÈÝÒס£ÕâÒѾ²»ÔÚ±¾ÎÄËùÌÖÂ۵ķ¶Î§ÖÐÁË¡£ </para> </section> <section id='migration4.strings'> - <title>Variable substitution in strings</title> + <title>×Ö·û´®ÖеıäÁ¿Ìæ»»</title> <para> - PHP 4 adds a new mechanism to variable substitution in - strings. You can now finally access object member variables and - elements from multidimensional arrays within strings. + PHP 4 Ìí¼ÓÁËÒ»¸öеĻúÖÆÒÔÌæ»»×Ö·û´®ÖеıäÁ¿¡£ÄúÏÖÔÚ¿ÉÒÔ·ÃÎÊ×Ö·û´®ÖеĶÔÏó³ÉÔ±±äÁ¿ºÍ¶àάÊý×éÔªËØ¡£ </para> <para> - To do so you have to enclose your variables with curly braces with - the dollar sign immediately following the opening brace: - <literal>{$...}</literal> + Èç¹ûÄúÏëÕâô×ö£¬ÄúÐèҪʹÓôóÀ¨ºÅ½«Ò»¸öÃÀÔª·ûºÅºÍ±äÁ¿ÃûÀ¨ÆðÀ´£¬¾ÍÏñÕâÑù£º<literal>{$...}</literal>¡£ </para> <para> - To embed the value of an object member variable into a string you - simply write <literal>"text {$obj->member} text"</literal> while - in PHP 3 you had to use something like <literal>"text - ".$obj->member." text"</literal>. + ÒªÔÚ×Ö·û´®ÖÐǶÈë¶ÔÏó³ÉÔ±±äÁ¿£¬Ö»Òª¼òµ¥µÄд <literal>"text {$obj->member} text"</literal>¡£¶øÔÚ PHP 3 ÖУ¬ÄúµÃʹÓà <literal>"text ".$obj->member." text"</literal>¡£ </para> <para> - This should lead to more readable code, while it may break - existing scripts written for PHP 3. But you can easily check for - this kind of problem by checking for the character combination - <literal>{$</literal> in your code and by replacing it with - <literal>\{$</literal> with your favorite search-and-replace - tool. + Õâ¸ö¸Ä½ø¿ÉÒÔʹ´úÂë¸üÒ×¶Á£¬µ«Õâ¿ÉÄÜ»áÆÆ»µÓà PHP 3 дµÄ´úÂë¡£µ«ÊÇÄúºÜÈÝÒ×ÐÞÕýËü£ºÔÚ´úÂëÖвéÕÒ×Ö·û´®ÖÐµÄ <literal>{$</literal>£¬Ê¹ÓÃËÑË÷Ìæ»»¹¤¾ß½«ËüÌæ»»Îª <literal>\{$</literal>¡£ </para> </section> <section id='migration4.cookies'> <title>Cookies</title> <para> - PHP 3 had the bad habit of setting cookies in the reverse order - of the <function>setcookie</function> calls in your code. PHP 4 - breaks with this habit and creates the cookie header lines in - exactly the same order as you set the cookies in the code. + PHP 3 ÔÚÉèÖà cookies ʱÓÐÒ»¸ö²»ºÃµÄϰ¹ß£¬Ëü×ÜÊǽ« <function>setcookie</function> ËùÉèÖÃµÄ cookies ÒÔÏà·´µÄ˳Ðò±£´æ¡£PHP 4 ¸Ä±äÁËÕâ¸öϰ¹ß£¬´´½¨ cookies ʱÒÔÄúµÄ´úÂëÖÐÉèÖà cookies µÄ˳Ðò±£´æ¡£ </para> <para> - This might break some existing code, but the old behaviour was so - strange to understand that it deserved a change to prevent further - problems in the future. + Õâ¿ÉÄÜʹµÃÔÓдúÂë²»ÄÜÕý³£¹¤×÷¡£µ«ÊÇ PHP 3 µÄÐÐΪµÄÈ·ºÜ¹Å¹Ö£¬Ó¦¸Ã¼ÓÒԸıäÒÔ·ÀÖ¹½«À´²úÉú¸ü¶àµÄÎÊÌâ¡£ </para> </section> <section id='migration4.variables'> - <title>Handling of global variables</title> + <title>´¦ÀíÈ«¾Ö±äÁ¿</title> <para> - While handling of global variables had the focus on to be easy in - PHP 3 and early versions of PHP 4, the focus has changed to be more - secure. While in PHP 3 the following example worked fine, in PHP 4 it - has to be unset($GLOBALS["id"]);. This is only one issue of global - variable handling. You should always have used $GLOBALS, with - newer versions of PHP 4 you are forced to do so in most cases. - Read more on this subject in the <link linkend="references.global"> - <literal>global</literal> references section</link>. + ÔÚ PHP 3 ºÍ PHP 4 ÔçЩ°æ±¾Öд¦ÀíÈ«¾Ö±äÁ¿µÄÖØÐÄ·ÅÔÚÁËÒ×ÓÃÉÏ£¬¶øÏÖÔÚ£¬½¹µã·Åµ½ÁËÈçºÎ¸ü°²È«µÄ´¦ÀíËüÃÇÉÏ¡£ÔÚ PHP 3 ÖÐÏÂÃæµÄ´úÂ빤×÷Õý³££¬µ«ÊÇ PHP 4 ÖоÍҪʹÓà unset($GLOBALS["id"]);¡£Õâ½ö½öÊÇÈ«¾Ö±äÁ¿´¦ÀíµÄÒ»¸öÎÊÌâ¡£ÄúÓ¦µ±×ÜÊÇʹÓà $GLOBALS£¬ÔÚ¸üа汾µÄ PHP 4 ÖÐÄúÓ¦¸ÃÇ¿ÆÈ×Ô¼ºÔڴ󲿷ÖÇé¿öÖÐʹÓÃËü¡£¸ü¶àÐÅÏ¢Çë²Î¿¼ <link linkend="references.global"> <literal>global</literal> ²Î¿¼Õ½Ú</link>. </para> <example> - <title>Migration of global variables</title> + <title>È«¾Ö±äÁ¿µÄÒÆÖ²</title> <programlisting role="php"> <![CDATA[ <?php @@ -379,7 +297,7 @@ unset($id); } test(); -echo($id); // This will print out 1 in PHP 4 +echo($id); // ÔÚ PHP 4 ÖÐÕâÀï»á´òÓ¡³ö 1 ?> ]]> </programlisting>