Gary Willoughby
Gary Willoughby

Reputation: 52578

Tools to highlight deprecated functions in PHP4 sources?

Is there any magic tools i can use to scan source code that was written for PHP4 to highlight deprecated functions in PHP5? I'm currently running the latest version of PHP on a server and need to port this code. Is there anything out there that can give me a hand?

Upvotes: 4

Views: 1611

Answers (3)

Ross
Ross

Reputation: 47057

The appendices of the manual contain some migration information but I don't think it contains what you're looking for.

One way (which might be inaccurate but could be used) I thought of was the news.txt included in each PHP download. I'm writing a script atm that parses this file and checking for deprecated functions could be something I could add. I am working on another project atm but I'd like to add functionality for this in the larger rebuilt version.

Upvotes: 0

Doug Kavendek
Doug Kavendek

Reputation: 3694

I wanted to do something like this myself. Using this list of deprecated features in PHP 5.3.x, I made a regex to search for any use of these functions:

(?i:(call_user_method\(|call_user_method_array\(|define_syslog_variables\(|dl\(|ereg\(|ereg_replace\(|eregi\(|eregi_replace\(|set_magic_quotes_runtime\(|session_register\(|session_unregister\(|session_is_registered\(|set_socket_blocking\(|split\(|spliti\(|sql_regcase\(|mysql_db_query\(|mysql_escape_string\())

(Case insensitive, with each function name including the opening parenthesis just to avoid false positives; "dl" would bring up lots of noise otherwise.)

If you're on a system with find and grep, you could then just execute something like this:

find <directory to search> -type f -name '*.php' -exec grep -R -P -H "<above regex>" {} \;

Just to make a more concrete example, I just used the following:

find htdocs -type f -name '*.php' -exec grep -R -P -H "(?i:(call_user_method\(|call_user_method_array\(|define_syslog_variables\(|dl\(|ereg\(|ereg_replace\(|eregi\(|eregi_replace\(|set_magic_quotes_runtime\(|session_register\(|session_unregister\(|session_is_registered\(|set_socket_blocking\(|split\(|spliti\(|sql_regcase\(|mysql_db_query\(|mysql_escape_string\())" {} \;

Looks like I now need to replace a few instances of session_register and session_unregister myself!

The same sort of thing could be done for deprecated INI directives and parameters.

Upvotes: 1

ceejayoz
ceejayoz

Reputation: 180065

PHP 5.3 will throw an E_DEPRECATED warning if you set your error reporting levels to show them.

Upvotes: 5

Related Questions