Using deprecated code in PHP5.3

When PHP5.3 was released I tested several open source projects on their compatibility with this new version. To my surprise a lot of them are not.

To clean up PHP some directives, functions or features that are going to be removed in PHP6. This will get rid of some potentially insecure or redundant features. Examples are the register_globals directive and the ereg regular expression functions. I haven't used these for at least the last 2 years, because I know that they are going to be removed in the future.

To detect the use of these deprecated features the new error level E_DEPRECATED has been introduced in PHP5.3. This enables developers to detect incompatibilies with the future release and learn how to improve their code. Because one can set the error reporting level, the deprecated messages can be switched off. This way developers are not required to immediately adapt their code, if they want to use PHP5.3.

Or so I thought. In php.ini you can disable DEPRECATED messages by setting which error levels should be reported:
error_reporting = E_ALL & ~E_DEPRECATED

Turns out that a lot of programmers are setting the error reporting inside their scripts/libraries, e.g. error_reporting(E_ALL). Probably they wanted to avoid STRICT messages. This takes precendence over the setting in php.ini. Meaning you will still get DEPRECATED messages. Thank you very much.

So now I have to decide what to do:

  • Remove the hard coded error_reporting() functions;
  • Rewrite the use of deprecated directives, functions and features;
  • Stick with PHP5.2

Linux distributions are still shipping PHP5.2 in the near future. So I probably will go with that temporary solution for now.

[Update] It is also a good idea to activate the "allow_call_time_pass_reference" PHP directive. In Apache you can add the following code to your VirtualHost or .htaccess to make PHP5.3 backward compatible.


php_flag allow_call_time_pass_reference On
php_value error_reporting "E_ALL & ~E_NOTICE & ~E_DEPRECATED"

PS. In PHP6 E_STRICT will be included in E_ALL. So you have been warned!