Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating to PHP 5.3 with deprecated functions warning disabled

I'm very keen to update a number of our servers to PHP 5.3. This would be in readiness for Zend Framework 2 and also for the apparent performance updates. Unfortunately, i have large amounts of legacy code on these servers which in time will be fixed, but cannot all be fixed before the migration. I'm considering updating but disabling the deprecated function error on all but a few development sites where i can begin to work through updating old code.

error_reporting(E_ALL ^ E_DEPRECATED);

Is there any fundamental reason why this would be a bad idea?

like image 233
robjmills Avatar asked Nov 05 '10 09:11

robjmills


People also ask

What does PHP deprecated mean?

The deprecation indicates the feature in question may be removed in the future. This warning refers to a line like $obj =& new MyClass(); The ampersand is not required any more since php 5; you can simply write $obj = new MyClass();

What is a deprecated error?

In information technology (IT), deprecation means that although something is available or allowed, it is not recommended or that -- in the case where something must be used -- to say it is deprecated means that its failings are recognized.


2 Answers

Well, you could forget that you set the flag and wonder why your application breaks in a next PHP update. It can be very frustrating to debug an application without proper error reporting. That's one reason I can think of.

However, if you do it, document it somewhere. It can save you a couple of hours before you remember setting the flag at all.

like image 121
TheGrandWazoo Avatar answered Sep 26 '22 13:09

TheGrandWazoo


If you haven't already you should read the migration guide with particular focus on Backward Incompatible Changes and Removed Extensions.

You have bigger issues than deprecation. Ignoring E_DEPRECATED will not suffice. Because of the incompatible changes there will also be other type of errors or, maybe, even worse, unexpected behaviors.

Here's a simple example:

<?php
function goto($line){
    echo $line;
}
goto(7);
?>

This code will work fine and output 7 in PHP 5.2.x but will give you a parse error in PHP 5.3.x.

What you need to do is take each item in that guide and check your code and update where needed. To make this faster you could ignore the deprecated functionality in a first phase and just disable error reporting for E_DEPRECATED, but you can't assume that you will only get some harmless warnings when porting to another major PHP branch.

Also don't forget about your hack and fix the deprecated issues as soon as possible.

Regards,
Alin

Note: I tried to answer the question from a practical point of view, so please don't tell me that ignoring warnings is bad. I know that, but I also know that time is not an infinite resource.

like image 42
Alin Purcaru Avatar answered Sep 26 '22 13:09

Alin Purcaru