robjmills
robjmills

Reputation: 18598

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?

Upvotes: 5

Views: 2615

Answers (3)

Nathan
Nathan

Reputation: 11159

I presume you have some kind of test server? If not, you really should set one up and test your code in PHP 5.3. If your code is thoroughly Unit Tested, testing it will take seconds, and fixing it will be fairly quick too, as the unit tests will tell you exactly where to look. If not, then consider making Unit Testing it all a priority before the next release, and in the meantime go through it all, first with E_DEPRECATED warnings disabled and fix anything which comes up, then with it re-enabled once you have time. You could also run a global find-and-replace for easier to fix errors.

Upvotes: 1

Alin P.
Alin P.

Reputation: 44356

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.

Upvotes: 3

TheGrandWazoo
TheGrandWazoo

Reputation: 2897

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.

Upvotes: 4

Related Questions