PHP Deprecated Errors in 5.3
MicroGuy | September 23, 2009In order to bring one of my billing servers into PCI Compliance, I found it necessary to upgrade PHP to version 5.3.
After the upgrade, my Apache error.log file came to life with two new PHP errors. Soon my tiny little error.log file had grown into a chubby error.log file because of these new PHP deprecated errors. Below, I will show you how to solve two types of errors and also how to suppress the errors if you need a quick “fix”.
1. Error: “Function set_magic_quotes_runtime() is deprecated”
Quick Fix (not recommended) : Suppress all PHP errors by adding ‘error_reporting(0);’ to the script, preferably in the config file if applicable.
Real Fix: In PHP 5, magic quotes are off by default, there is no need to turn them off. The error message will contain the file and line generating this error. Fire up your text editor and make the following changes to the code. Oh, and don’t forget to back up the file before the hackfest begins.
Find this code:
set_magic_quotes_runtime(0);
Replace with this code:
// added to fix notice when upgrading to PHP 5.3
if(version_compare(PHP_VERSION, ’5.3.0′, ‘<’))
{
set_magic_quotes_runtime(0);
}
2. Error: “Assigning the return value of new by reference is deprecated”
Quick Fix (not recommended) : Suppress all PHP errors by adding ‘error_reporting(0);’ to the script, preferably in the config file if applicable.
Real Fix: In PHP 5 objects are always passed by reference. You can remove reference operators and it will still work as you want. Find the line generating the error and follow these easy instructions. Backup before the hack attack.
Find any code containing the ‘&’ symbol and remove it: (for example)
$t = & new Fraction( $i );
Replace with this code:
// edit to fix notice when upgrading to PHP 5.3
$t = new Fraction( $i );
Feel free to post any questions in the comments section. I hope this helps someone save a little time. Enjoy!


