Php 5 to 7 deprecated functions

I have a website on a server with php 4.4. (Yes, it exists)

I must move it on an other hosting with php 7 I've tried in local, and it's full of errors and nothing works.

For "scan" the files, I want make a script to find the old function and, after, one by one, "repair". Most of .php are "dirty scripts", not well organised but my job is only to move this website and adapt it to php7.

But, I need to find the list of deprecated or incompatible functions from Php 4.4 to Php 7.

Where can I find such a list???

UPDATE:

I've find most of the problems in the main files (most problems are ereg function and mysql -> mysqli). In the same time, I simplified the scripts because the developer used the same function with different name many times (8 times in the same file, with 8 different names -_-) So I've made a function.php where I put all functions and I include it in the files.

It's not easy to work after a dirty developer -_-

by Vincy. Last modified on July 19th, 2022.

If you have to come this article now with an intention to migrate your website from PHP 5.6 to PHP 7, first please be aware. Your time is already over. This is too late. Somehow you should get this done now. Do not postpone this work beyond this moment.

This is an overwhelming task. We never know what will break. For now things are running smooth with the website. If we migrate the version to PHP 7, we do not know if it will run or not. So everybody keeps postponing this sensitive task.

Fear not, I will guide you through this migration journey. I have done it for many shopping cart, financial domain and critical websites. I have sound experience doing this and you can bank on me. I will present you my experience doing these migrations.

Upgrading the setup or development or server environment to PHP 7

I will guide you for the migration of the PHP application or website only. Upgrading the server environment like Apache version or the installed PHP version can be dealt with another article. It is a sysadmin thing.

If you are on a shared web hosting server, you will have an option in your control panel. It should be a single click easy work. Otherwise your hosting provider will do it for you. You may have to raise a ticket to get it done. Unless if you are in a dedicated server environment, you need not worry about.

Whatsoever, migration of the website or the PHP application should be done by you. It is not in the hosting provider or sysadmin’s scope. It should be done by the PHP developer.

PHP versions, support and EOL

Why now? What is the necessity to migrate PHP 5.6 to PHP 7 now? Before going into why, you should know about the PHP versions, their support duration and EOL details. It will give you the answers.

Php 5 to 7 deprecated functions

Ref: https://www.php.net/supported-versions.php

Why should you migrate from PHP 5.6?

PHP 5.6 version active releases ended in early 2017 and reached its end of life (EOL) by 2018 end. That was once upon a time and long long ago. After PHP 5.6, we had PHP 7.0, 7.1, … and the current live version is 7.4

My longtime client recently forward an email he got from his hosting provider. His website is hosted with a popular shared hosting server.

The hosting provider has given ten days time to upgrade from PHP 5.6 to PHP 7.2 Even they have asked to migrate PHP 7.0 and PHP 7.1 to PHP 7.2 If the upgrade is not done within the given time frame, the hosting provider will upgrade the PHP version to 7.2 themselves.

This timeframe is to allow migrate the website to be compatible with 7.2. The control panel allows to change the PHP versions back and forth.

If you are in a shared hosting server environment, you will be forced to migrate anytime soon. You better make the move yourself, so that you can plan and execute at your convenience.

Security

If there is one reason that stands on top of everything is security. There are many vulnerabilities that are being exposed to public daily. When there is a known vulnerability, PHP team will release a fix.

But if the PHP version has reached it EOL, then there will not be a release. Your website will stand exposed inviting the hackers. So it is important to migrate your website to a PHP version that is being supported. Upgrade your old PHP now!

Performance

There are numerous studies published and circulated widely. PHP 7 has, “100%+ performance gain on most real-world applications” says Rasmus Lerdorf (Ref: http://talks.php.net/fluent15#/php7) This is from his slides from PHP 7 talk at fluentconf. The good performance due to low latency is widely acknowledged.

Php 5 to 7 deprecated functions

So how does good performance help your website? For one second lag, you will loose a minimum of 10% visitors. Search engines give priority to fast loading websites. Are these two reasons not enough?

As published by Christian Vigh, PHP 7 is faster by a whooping 400% than PHP 5.2

Php 5 to 7 deprecated functions

Ref: https://www.phpclasses.org/blog/post/493-php-performance-evolution.html#performance

New PHP features

Developers should be armed with good set of tools. When the language gives a good set of features, that enables the developer to produce a good product. Following are some of the features that are available in PHP 7.

  • The null coalescing operator
  • Return and scalar type declarations
  • Anonymous Classes
  • Zero cost asserts
  • Typed properties 2.0
  • Preloading
  • Null coalescing assignment operator
  • Improve openssl_random_pseudo_bytes
  • Weak references
  • New custom object serialization mechanism
  • Password hash registry
  • Covariant returns and contravariant parameters
  • Spread operator in array expression
  • Multi-catch exceptions
  • Keys usable in lists

Backwards compatibility

This is the key thing to focus on website migration. You might have used a feature that is available only in the lower version and removed in the newer version. Here is a list of backward incompatible changes between PHP 5.6 and PHP 7.0

  • set_exception_handler() is no longer guaranteed to receive Exception objects
  • Internal constructors always throw exceptions on failure
  • Parse errors throw ParseError
  • list() no longer assigns variables in reverse order
  • Empty list() assignments have been removed
  • list() cannot unpack strings
  • Array ordering when elements are automatically created during by reference assignments has changed
  • Parentheses around function arguments no longer affect behaviour
  • foreach no longer changes the internal array pointer and more changes.
  • Changes to Division By Zero and more integer handling changes.
  • Hexadecimal strings are no longer considered numeric and more string handling changes.
  • All ext/mysql functions and more list of functions removed.
  • New objects cannot be assigned by reference
  • Switch statements cannot have multiple default blocks
  • JSON extension replaced with JSOND

The above list is a summary only. Go through Ref: https://www.php.net/manual/en/migration70.incompatible.php for the complete list.

Deprecated features in PHP 7.0

So you are going to move forward. Know about what you should not use going forward. If you have already used the deprecated features, then it is better to migrate them also. Here is a list the deprecated list.

  • PHP 4 style constructors
  • Static calls to non-static methods
  • password_hash() salt option
  • capture_session_meta SSL context option
  • ldap_sort() function is deprecated.

More list of changes to keep an eye on

  • Certain functions arguments and return types are changed. (Ref: https://www.php.net/manual/en/migration70.changed-functions.php)
  • New functions, classes and interfaces are added. (Ref: https://www.php.net/manual/en/migration70.classes.php)
  • New global constants are added (Ref: https://www.php.net/manual/en/migration70.constants.php)
  • Unqualified listen ports now listen on both IPv4 and IPv6
  • List of extensions SAPIs are removed (Ref: https://www.php.net/manual/en/migration70.removed-exts-sapis.php)

Steps to do the PHP website migration

  1. Backup your website, application, database, data in disk.
  2. Check if your hosting provider or your environment will allow to rollback the PHP version. This will be helpful if in case you are stuck at some point.
  3. Check the PHP compatibility for the respective version of the dependent vendor applications, plugins, modules and extensions.
  4. Prepare a checklist for items to be changed for backwards incompatibility. Refer above for consolidated list.
  5. Add the deprecated items to the checklist. Refer above for consolidated list.
  6. Use a well equipped IDE. Detach the old dependent PHP library and then add the new to be migrated PHP library. The IDE will warn and show errors. I promise, this will be helpful. If you are a person using a plain texteditor, then now is the time to dump it.
  7. Refactor the code.
  8. Deploy in a staging environment.
  9. Test.
  10. Go live.

↑ Back to Top

Which functions are deprecated in PHP 7?

PHP 7 - Deprecated Features.
PHP 4 style constructors. PHP 4 style Constructors are methods having same name as the class they are defined in, are now deprecated, and will be removed in the future. ... .
Static calls to non-static methods. ... .
Example. ... .
password_hash() salt option. ... .
capture_session_meta SSL context option..

Which PHP tag style is deprecated in PHP version 7?

PHP 4 style constructors (methods that have the same name as the class they are defined in) are deprecated, and will be removed in the future. PHP 7 will emit E_DEPRECATED if a PHP 4 constructor is the only constructor defined within a class. Classes that implement a __construct() method are unaffected.

What is the main difference between PHP 5 and PHP 7?

PHP 5 does not allow programmers to specify the return type of a function or method. PHP 7 enables programmers to declare the return type of the functions as per the expected return value. Thus, it makes the code robust and accurate. It is quite challenging to handle fatal errors in PHP 5.

Is PHP 7 backwards compatible?

PHP 7 is not backwards compatible.