Upgrading PHP/MySQL Application with Migration from PHP4 to PHP5
As the suppport for PHP4 is ending on August 8, 2008 as announced by PHP development team, it is required that everybody migrate their PHP environment to PHP5 ASAP. This requires some upgrades (we cannot tell just modifications, as there are goodies!) to make the existing applications in PHP4 to work with PHP5.
The major thing you need to be worried is use of Superglobal variables. Though these variables (associative arrays available by default) are a part of PHP4.3 onwards, the mandatory requirement has been forced with PHP5. The major variables are $_GET, $_POST, $_SERVER, $_COOKIE, $_FILES, and $_SESSION. Difference is that in earlier versions of PHP4, when you post a form, a variable in the name of for element is available. For example, let us have a look at the following form:
- <form id="frmTest" action="<?php print $_SERVER[PHP_SELF];?>" method="post">
- <input type="text"name="txtName"id="txtName" value=""/>
- <input type="submit" name="btnTest" id="btnTest" value=Submit" />
- </form>
Now upon submitting the form in case of PHP4, the value of textbox txtName will be avilable in a PHP variable named $txtName. Of course, in PHP4, you decide whether to register EGPCS (Environment, GET, POST, Cookie, Server) variables as global variables or not by adjusting the PHP configuration directive register_globals = off or on in php.ini. With the PHP versions 4.2.0 onwards, this directive defaults to off. You can also set php_flag register_globals off or on in .htaccess. On a side note, you can see the use of another superglobal variable $_SERVER in the above form.
In the migration to PHP5, the best way out is to define a variable in the begining of the file as
- $txtName=$_POST['txtName']
and then you achieve the migration smoothly.
Other aspects of migration are related to performance, and use of different inbuilt functions and libraries may be required if you want to use the full power of PHP5. However, your migration should be achieved with the simple step above.