Anyone who is messing around with amfphp and has updated their PHP to version 5.3.0 or updated their Wampserver to version 2.0i, using PHP 5.3.0, will probably have encountered the following warning message :
Function eregi_replace() is deprecated
The error message is thrown because since PHP 5.3.0 the function eregi_replace(), used in one of the amfphp core php files, has indeed become deprecated.
This warning message will not only get thrown when using amfphp, any use of the eregi_replace() function will of course trigger this warning.
For those who are not that familiar with the term “deprecated” , it means that the function has been put out of use because there is a better equivalent now. The function still exists and works but the people of PHP would like it if you stop using it so they can let it slowly disappear.
You can do two things about this small problem :
- Change the settings in your php.ini file to disable the deprecated warnings.
- Replace the php code in that specific amfphp core file, using the new equivalent function.
I suggest you do the second, but either one works. The first solution is not ideal because it will prevent PHP from throwing any warnings concerning notices and coding standards. Some of these are useful when developing.
1. Change the php.ini file
Locate the php.ini file, you will normally find the php.ini file in the bin directory of your webserver. If you are indeed using Wampserver, you can easily open your php.ini file by clicking the wampserver icon in your tray and selecting PHP > php.ini . This will open the php.ini file in your text editor. Now search (you might want to use the search function) for “error_reporting =”. This will be set to the default value which is “error_reporting = E_ALL”. Changing this to “error_reporting = E_ALL & ~E_NOTICE” will prevent PHP from throwing warnings concerning notices and coding standards. Only the errors will get thrown. Now save and close the php.ini file and restart your server.
2.Change the deprecated code
This example is only suitable in the case of amfphp and wampserver, of course the method of changing the deprecated code will work in other cases as well. You can use this code as an example to alter the deprecated code in other cases.
So, in the case of amfphp the deprecated code is located in the MethodTable.php file. At line 505 to be exact. You will find the MethodTable.php file at “C:\wamp\www\amfphp\core\shared\util\” , assuming your wampserver is placed at the root of your C drive and amfphp at the root of your webserver. Anyway, when the warning message gets thrown, the exact location of the MethodTable.php file is mentioned. When found, open the MethodTable.php file in an editor and alter the following.
Go to line 505 and remove, or comment, the following lines of code :
$comment = eregi_replace(“\n[ \t]+”, “\n”, trim($comment))
$comment = str_replace(“\n”, “\\n”, trim($comment));
$comment = eregi_replace(“[\t ]+”, ” “, trim($comment));
Then replace it with the following code, using the equivalent function preg_replace() :
$comment = preg_replace(“`\n[ \t]+`U”, “\n”,trim($comment));
$comment = str_replace(“\n”, “\\n”, trim($comment));
$comment = preg_replace(“`[\t ]+`U”, ” “,trim($comment));
Save and close the MethodTable.php file. Restarting your webserver is not necessary but is a good idea.
These solutions should have resolved the deprecated eregi_replace() issue.
Code on !
Filed under: Uncategorized , php;5.3.0;amfphp;eregi_replace();deprecated