r/PHPhelp • u/kuhhlboy • 27d ago
Patching code full of old syntax/functions
Hello,
I am patching some php code of some kind of DB web integration and the code is quite old. After giving it into phpstorm to check for problems, it showed dozens of syntax errors (mostly curly braces for accessing array elements, no big deal in changing them to squared ones) and whole functions that arent supported anymore. Mostly things as MYSQL_BOTH, MYSQL_NUM, etc. Is there a nice way to fix those issues, maybe even some kind of software, or do I need to manually rewrite those passages w/o the functions?
7
Upvotes
View all comments
6
u/allen_jb 27d ago
I would recommend Rector over AI for this.
Rector is based on running sets of fixed, known, tested rules to transform code in a reliable way.
Note that if the code uses the old
mysql_*functions (ext/mysql), I don't think Rector currently handles upgrading these. You might want to try searching for mysql shim on Packagistext/mysql usage should ideally be upgraded to use PDO MySQL or mysqli. Note: While the mysqli procedural functions may look similar, there are significant differences that make switching non-trivial through simple search and replace.
You may also want to look at the PHPCompatibility ruleset for CodeSniffer
If you need further help I would suggest including the PHP version the code is currently running on.