r/PHPhelp • u/kuhhlboy • 29d 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?
8
Upvotes
View all comments
Show parent comment
1
u/allen_jb 27d ago
As far as I'm aware there's no specific issues with dshafik's library other than that the author doesn't wish to maintain it.
There are several alternatives, which is one reason I linked to the packagist search instead of direct to a specific library.
And yes, as I stated in my reply, ideally these usages should be upgraded to use mysqli or PDO, but developers don't always live in an ideal world. I've performed upgrades of old codebases and there can be a lot to deal with all at once, so using a shim library temporarily can allow developers to quickly solve one problem (temporarily, hopefully) while they solve others.
For example, use a shim library to allow updating the rest of the code with Rector, then the shim can be replaced with modern PDO / mysqli code, taking full advantage of things like the recent addition of ->execute_query in mysqli.
As a quick addition to my original reply, I'll also add that DB calls should ideally be upgraded to use prepared queries where possible to avoid potential bugs in incorrect escaping as well as avoiding SQL injection.