loading...

PHP5 to PHP7 code migration steps for the medium or large code base.

suryanarayana profile image SURYA NARAYANA MURTHY Updated on ・2 min read

Note: The original detailed article is posted in https://www.nalashaa.com/php5-to-php7-migration/ by me.

Php 7 has come with really good features in that most important things are improved in performance, lower memory consumption, many fatal errors converted to exceptions.

Steps to upgrade from PHP5 to PHP7:
Three main things are there while doing the upgrade. This below process will be helpful if your code base is medium or large.
1) Choosing an IDE (Jet Brains, Net Beans, Eclipse, and Visual Studio Code, etc.).
2) The code upgrade process.
3) Testing phase.

Choosing an IDE:
While doing an upgrade it is hard to know about all the deprecated and removed functions manually, to solve this issue smart IDE will be helpful.
1) Choose a smart IDE and set the environment to PHP 5.6 in that.
2) Open your entire project in IDE and check for the errors and suggestions given by IDE to refactor the code.
Note: To see the deprecated suggestions from IDE the configurations have to set properly.
3) If possible do refactoring in localhost rather than in development server connected via SSH.
4) Doing it in localhost will help us in saving the development time and also we can keenly monitor the deprecated and removed functions.

Code Upgrade Process:
Resolve all the errors including notice errors, deprecated errors in PHP 5.6.* then your code will run in PHP 7.0 version.
1) Set error reporting to E_ALL as below. Eg: error_reporting(E_ALL ^ E_STRICT);
2) Solve all the errors including notice errors and deprecated errors.
3) If the codebase is large then just resolve the errors to make it work in PHP 7.0. Then you can re-write your code module by module based on your feasibility.
4) If you are not using mysql_* extension in your old version it would be easy to upgrade otherwise it will take time, based on your code base size.
5) If you are using mysql_* extension to make your work simple try to replace it with mysqli_* so that it will be easy to upgrade. If you have time to upgrade then create an abstraction layer for database operations by using PDO extension because PDO supports multiple databases.

Testing Phase:
1) Maintain the logs for database errors, as like you should receive a mail and that you will get
2) Create the logs for php errors date wise.
3) Create a new testing server i.e. it should be a copy of production server and release it few customers for testing and monitor.
4) If everything is ok you can move it to production.

Note: The original detailed article is posted in https://www.nalashaa.com/blog/ by me.

Posted on by:

suryanarayana profile

SURYA NARAYANA MURTHY

@suryanarayana

Being a Web Developer I do continuously learning new technologies and applying it in projects.

Discussion

markdown guide