As promised in Part 1, I’m documenting yet another issue that must be addressed in your AMFPHP installation upon upgrading to PHP 5.3. This issue stems from the usage of the [code lang="php"]eregi_replace[/code] function that has been deprecated in PHP 5.3. If you run into a fatal error in your AMFPHP application with the message [code]Function eregi_replace() is deprecated[/code], you have (2) options:
- Modify your PHP configuration to disable the warnings
- Replace the deprecated code with the new, recommended equivalent
I’d advise against #1 since you will also lose warning and error notices that could be helpful to you during development. And, by choosing #2 you will be bringing the AMFPHP code into compliance with a change that is also backwards-compatible with previous versions of PHP since the replacement function you’re going to use has been around since PHP 4.
So, to update your AMFPHP source, you need to modify [code]MethodTable.php[/code] which can be found @ [code]/path/to/amfphp/core/shared/util/MethodTable.php[/code]. Open up this file in your favorite text editor (ie, TextMate
) and jump to line 505. Once there, you need to replace these three lines:
$comment = eregi_replace(”\n[ \t]+”, “\n”, trim($comment)); $comment = str_replace(”\n”, “\\n”, trim($comment)); $comment = eregi_replace(”[\t ]+”, ” “, trim($comment));
with these equivalent lines of code:
$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 file, fire up your service browser and you should now be good to go with no more fatal errors in your AMFPHP applications produced by this deprecated function. Happy coding!


