From 3db601871cd793d118fb33dd96dc210a0f55c8c7 Mon Sep 17 00:00:00 2001 From: Gabor Hojtsy Date: Sun, 14 Oct 2001 14:29:26 +0000 Subject: [PATCH] Moving all 3.0 => 4.0 migration into migration4.xml, many many WS fixes in migration.xml git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@59927 c90b9560-bf6c-de11-be94-00142212c4b1 --- appendices/migration.xml | 597 ++++++++++++++++---------------------- appendices/migration4.xml | 114 +++++++- 2 files changed, 368 insertions(+), 343 deletions(-) diff --git a/appendices/migration.xml b/appendices/migration.xml index 4d60a7d49a..9776712f4a 100644 --- a/appendices/migration.xml +++ b/appendices/migration.xml @@ -1,215 +1,105 @@ - + - Migrating from older versions of PHP + Migrating from PHP/FI 2.0 to PHP 3.0 + +
+ About the incompatibilities in 3.0 - - Migrating from PHP 3 to PHP 4 - Migration from PHP 3 to PHP 4 is relatively easy, and should - not require you to change your code in any way. There are - minor incompatibilities between the two versions; You may want - to check the incompatibilities list to make sure that you're - indeed not affected by them (the chances you're affected by - these incompatibilities are extremely slim). + PHP 3.0 is rewritten from the ground up. It has a proper parser + that is much more robust and consistent than 2.0's. 3.0 is also + significantly faster, and uses less memory. However, some of + these improvements have not been possible without compatibility + changes, both in syntax and functionality. - - - Running PHP 3 and PHP 4 concurrently - - Recent operating systems provide the ability to perform - versioning and scoping. This features make it possible to let - PHP 3 and PHP 4 run as concurrent modules in one Apache server. - - - This feature is known to work on the following platforms: - - - Linux with recent binutils (binutils 2.9.1.0.25 tested) - Solaris 2.5 or better - FreeBSD (3.2, 4.0 tested) - - - To enable it, configure PHP3 and PHP4 to use APXS - (--with-apxs) and the necessary link extensions - (--enable-versioning). Otherwise, all standard installations - instructions apply. For example: - -$ ./configure \ - --with-apxs=/apache/bin/apxs \ - --enable-versioning \ - --with-mysql \ - --enable-track-vars - - - - - Migrating Configuration Files - - Global Configuration File - - The global configuration file, php3.ini, has changed its name to php.ini. - - - - Apache Configuration Files - - The MIME types recognized by the PHP module have changed. - -application/x-httpd-php3 --> application/x-httpd-php -application/x-httpd-php3-source --> application/x-httpd-php-source - - - - You can make your configuration files work with both versions - of PHP (depending on which one is currently compiled into the - server), using the following syntax: - -AddType application/x-httpd-php3 .php3 -AddType application/x-httpd-php3-source .php3s + + In addition, PHP's developers have tried to clean up both PHP's + syntax and semantics in version 3.0, and this has also caused some + incompatibilities. In the long run, we believe that these changes + are for the better. + -AddType application/x-httpd-php .php -AddType application/x-httpd-php-source .phps - - - - In addition, the PHP directive names for Apache have changed. - - - Starting with PHP 4.0, there are only four Apache directives - that relate to PHP: - -php_value [PHP directive name] [value] -php_flag [PHP directive name] [On|Off] -php_admin_value [PHP directive name] [value] -php_admin_flag [PHP directive name] [On|Off] - - - - There are two differences between the Admin values and the non admin values: - - - Admin values (or flags) can only appear in the server-wide apache configuration files (e.g., httpd.conf). - Standard values (or flags) cannot control certain PHP directives, for example - safe mode (if you could override safe mode settings in .htaccess files, it would defeat safe-mode's purpose). In contrast, Admin values can modify the value of any PHP directive. - - - To make the transition process easier, PHP 4.0 is bundled with scripts that automatically convert your Apache configuration and .htaccess files to work with both PHP 3.0 and PHP 4.0. These scripts do NOT convert the mime type lines! You have to convert these yourself. - - - To convert your Apache configuration files, run the apconf-conv.sh script (available in the scripts/apache/ directory). For example: - -~/php4/scripts/apache:# ./apconf-conv.sh /usr/local/apache/conf/httpd.conf - - - - Your original configuration file will be saved in httpd.conf.orig. - - - To convert your .htaccess files, run the aphtaccess-conv.sh script (available in the scripts/apache/ directory as well): - -~/php4/scripts/apache:# find / -name .htaccess -exec ./aphtaccess-conv.sh {} \; - - - - Likewise, your old .htaccess files will be saved with an .orig prefix. - - - The conversion scripts require awk to be installed. - - + + This chapter will try to guide you through the incompatibilities + you might run into when going from PHP/FI 2.0 to PHP 3.0 and help + you resolve them. New features are not mentioned here unless + necessary. + - - + + A conversion program that can automatically convert your old + PHP/FI 2.0 scripts exists. It can be found in the convertor subdirectory of the PHP 3.0 + distribution. This program only catches the syntax changes though, + so you should read this chapter carefully anyway. + +
- - Migrating from PHP/FI 2.0 to PHP 3.0 +
+ Start/end tags - - About the incompatibilities in 3.0 - - PHP 3.0 is rewritten from the ground up. It has a proper parser - that is much more robust and consistent than 2.0's. 3.0 is also - significantly faster, and uses less memory. However, some of - these improvements have not been possible without compatibility - changes, both in syntax and functionality. - - - In addition, PHP's developers have tried to clean up both PHP's - syntax and semantics in version 3.0, and this has also caused some - incompatibilities. In the long run, we believe that these changes - are for the better. - - - This chapter will try to guide you through the incompatibilities - you might run into when going from PHP/FI 2.0 to PHP 3.0 and help - you resolve them. New features are not mentioned here unless - necessary. - - - A conversion program that can automatically convert your old - PHP/FI 2.0 scripts exists. It can be found in the convertor subdirectory of the PHP 3.0 - distribution. This program only catches the syntax changes though, - so you should read this chapter carefully anyway. - - - Start/end tags - - - The first thing you probably will notice is that PHP's start and end - tags have changed. The old <? > form has been - replaced by three new possible forms: - - Migration: old start/end tags - + + The first thing you probably will notice is that PHP's start and end + tags have changed. The old <? > form has been + replaced by three new possible forms: + + Migration: old start/end tags + <? echo "This is PHP/FI 2.0 code.\n"; > - - - As of version 2.0, PHP/FI also supports this variation: - - Migration: first new start/end tags - + + + As of version 2.0, PHP/FI also supports this variation: + + Migration: first new start/end tags + <? echo "This is PHP 3.0 code!\n"; ?> - + + - 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: + 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: - Migration: second new start/end tags - + + Migration: second new start/end tags + <?php echo "This is PHP 3.0 code!\n"; ?> - + + - 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: + 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: - Migration: third new start/end tags - + + Migration: third new start/end tags + <script language="php"> echo "This is PHP 3.0 code!\n"; </script> - + + + +
+
+ if..endif syntax - - if..endif syntax - - - 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: - - Migration: old if..endif syntax - + + 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: + + Migration: old if..endif syntax + if ($foo); echo "yep\n"; elseif ($bar); @@ -217,10 +107,11 @@ elseif ($bar); else; echo "nope\n"; endif; - - - Migration: new if..endif syntax - + + + + Migration: new if..endif syntax + if ($foo): echo "yep\n"; elseif ($bar): @@ -228,48 +119,56 @@ elseif ($bar): else: echo "nope\n"; endif; - + + - Notice that the semicolons have been replaced by colons in all - statements but the one terminating the expression (endif). + Notice that the semicolons have been replaced by colons in all + statements but the one terminating the expression (endif). + +
- - while syntax - - Just like with if..endif, the syntax of while..endwhile has changed - as well: - Migration: old while..endwhile syntax +
+ while syntax + + Just like with if..endif, the syntax of while..endwhile has changed + as well: + + Migration: old while..endwhile syntax while ($more_to_come); ... endwhile; - - Migration: new while..endwhile syntax + + + + Migration: new while..endwhile syntax while ($more_to_come): ... endwhile; - - - - - If you use the old while..endwhile syntax in PHP 3.0, you will get - a never-ending loop. - - - - - Expression types + + + + - 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. - + If you use the old while..endwhile syntax in PHP 3.0, + you will get a never-ending loop. + + +
- - Consider this example: - +
+ Expression types + + 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. + + + Consider this example: + + $a[0]=5; $a[1]=7; @@ -278,152 +177,166 @@ while ("" != $key) { echo "$keyn"; next($a); } - + + - 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 "" does not equal - "0", 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 atoi("") which is - 0, and variablelist which is - also 0, and since 0==0, the - loop doesn't go through even once. - - - - The fix for this is simple. Replace the while statement with: - + 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 "" does not equal + "0", 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 atoi("") which is + 0, and variablelist which is + also 0, and since 0==0, the + loop doesn't go through even once. + + + The fix for this is simple. Replace the while statement with: + + while ((string)$key != "") { - + + + +
+
+ Error messages have changed + + 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. + +
- - Error messages have changed - - 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. - +
+ Short-circuited boolean evaluation + + In PHP 3.0 boolean evaluation is short-circuited. This means that + in an expression like (1 || test_me()), the + function test_me would not be executed since + nothing can change the result of the expression after the + 1. + + + This is a minor compatibility issue, but may cause unexpected + side-effects. + +
- - Short-circuited boolean evaluation - - In PHP 3.0 boolean evaluation is short-circuited. This means that - in an expression like (1 || test_me()), the - function test_me would not be executed since - nothing can change the result of the expression after the - 1. - - - This is a minor compatibility issue, but may cause unexpected - side-effects. - - - - Function &true;/false return values - - 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 $fp = fopen("/your/file") or - fail("darn!");. 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. - - - Migration from 2.0: return values, old code - +
+ Function &true;/&false; return values + + 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 $fp = fopen("/your/file") or + fail("darn!");. 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. + + + + Migration from 2.0: return values, old code + $fp = fopen($file, "r"); if ($fp == -1); echo("Could not open $file for reading<br>\n"); endif; - - - - Migration from 2.0: return values, new code - + + + + Migration from 2.0: return values, new code + $fp = @fopen($file, "r") or print("Could not open $file for reading<br>\n"); - - + + + +
- - - Other incompatibilities +
+ Other incompatibilities - - - The PHP 3.0 Apache module no longer supports Apache versions - prior to 1.2. Apache 1.2 or later is required. + + + The PHP 3.0 Apache module no longer supports Apache versions + prior to 1.2. Apache 1.2 or later is required. + - echo no longer - supports a format string. Use the - printf function instead. + + echo no longer supports a format string. + Use the printf function instead. + - - In PHP/FI 2.0, an implementation side-effect caused - $foo[0] to have the same effect as - $foo. This is not &true; for PHP 3.0. + + In PHP/FI 2.0, an implementation side-effect caused + $foo[0] to have the same effect as + $foo. This is not true for PHP 3.0. + - - Reading arrays with $array[] is no longer - supported + + + Reading arrays with $array[] is no longer + supported + + + That is, you cannot traverse an array by having a loop that does + $data = $array[]. Use current + and next instead. + + + Also, $array1[] = $array2 does not + append the values of $array2 to + $array1, but appends + $array2 as the last entry of + $array1. See also multidimensional array + support. + + - - That is, you cannot traverse an array by having a loop that does - $data = $array[]. Use - current and next - instead. - - Also, $array1[] = $array2 does not append the - values of $array2 to $array1, - but appends $array2 as the last entry of - $array1. See also multidimensional array - support. + + + "+" is no longer overloaded as a + concatenation operator for strings, instead it converts it's + arguments to numbers and performs numeric addition. Use + "." instead. + + + - - "+" is no longer overloaded as a - concatenation operator for strings, instead it converts it's - arguments to numbers and performs numeric addition. Use - "." instead. - - - - Migration from 2.0: concatenation for strings - + + Migration from 2.0: concatenation for strings + echo "1" + "1"; - - - - In PHP 2.0 this would echo 11, in PHP 3.0 it would echo 2. Instead - use: - - + + + In PHP 2.0 this would echo 11, in PHP 3.0 it would + echo 2. Instead use: + echo "1"."1"; - - - + + $a = 1; $b = 1; echo $a + $b; - - - - This would echo 2 in both PHP 2.0 and 3.0. - - + + + + This would echo 2 in both PHP 2.0 and 3.0. + $a = 1; $b = 1; echo $a.$b; - - This will echo 11 in PHP 3.0. - - + + This will echo 11 in PHP 3.0. + + +
diff --git a/appendices/migration4.xml b/appendices/migration4.xml index a584a3e7f8..739d203c26 100644 --- a/appendices/migration4.xml +++ b/appendices/migration4.xml @@ -1,8 +1,120 @@ - + Migrating from PHP 3.0 to PHP 4.0 + + Migration from PHP 3 to PHP 4 is relatively easy, and should + not require you to change your code in any way. There are + minor incompatibilities between the two versions. You may want + to check the incompatibilities list to make sure that you're + indeed not affected by them (the chances you're affected by + these incompatibilities are extremely slim). + + +
+ Running PHP 3 and PHP 4 concurrently + + Recent operating systems provide the ability to perform + versioning and scoping. This features make it possible to let + PHP 3 and PHP 4 run as concurrent modules in one Apache server. + + + This feature is known to work on the following platforms: + + + Linux with recent binutils (binutils 2.9.1.0.25 tested) + Solaris 2.5 or better + FreeBSD (3.2, 4.0 tested) + + + To enable it, configure PHP3 and PHP4 to use APXS + (--with-apxs) and the necessary link extensions + (--enable-versioning). Otherwise, all standard installations + instructions apply. For example: + +$ ./configure \ + --with-apxs=/apache/bin/apxs \ + --enable-versioning \ + --with-mysql \ + --enable-track-vars + + +
+ +
+ Migrating Configuration Files + + The global configuration file, php3.ini, + has changed its name to php.ini. + + + For the Apache configuration file, there are slightly more + changes. The MIME types recognized by the PHP module have + changed. + +application/x-httpd-php3 --> application/x-httpd-php +application/x-httpd-php3-source --> application/x-httpd-php-source + + + + You can make your configuration files work with both versions + of PHP (depending on which one is currently compiled into the + server), using the following syntax: + +AddType application/x-httpd-php3 .php3 +AddType application/x-httpd-php3-source .php3s + +AddType application/x-httpd-php .php +AddType application/x-httpd-php-source .phps + + + + In addition, the PHP directive names for Apache have changed. + + + Starting with PHP 4.0, there are only four Apache directives + that relate to PHP: + +php_value [PHP directive name] [value] +php_flag [PHP directive name] [On|Off] +php_admin_value [PHP directive name] [value] +php_admin_flag [PHP directive name] [On|Off] + + + + There are two differences between the Admin values and the non admin values: + + + Admin values (or flags) can only appear in the server-wide apache configuration files (e.g., httpd.conf). + Standard values (or flags) cannot control certain PHP directives, for example - safe mode (if you could override safe mode settings in .htaccess files, it would defeat safe-mode's purpose). In contrast, Admin values can modify the value of any PHP directive. + + + To make the transition process easier, PHP 4.0 is bundled with scripts that automatically convert your Apache configuration and .htaccess files to work with both PHP 3.0 and PHP 4.0. These scripts do NOT convert the mime type lines! You have to convert these yourself. + + + To convert your Apache configuration files, run the apconf-conv.sh script (available in the scripts/apache/ directory). For example: + +~/php4/scripts/apache:# ./apconf-conv.sh /usr/local/apache/conf/httpd.conf + + + + Your original configuration file will be saved in httpd.conf.orig. + + + To convert your .htaccess files, run the aphtaccess-conv.sh script (available in the scripts/apache/ directory as well): + +~/php4/scripts/apache:# find / -name .htaccess -exec ./aphtaccess-conv.sh {} \; + + + + Likewise, your old .htaccess files will be saved with an .orig prefix. + + + The conversion scripts require awk to be installed. + +
+
What has changed in PHP 4.0