Updating to PHP 8.0 is there a tool to look for expired code?

Hi,
I have recently upgraded to PHP8.0 and have
noticed that a few Wordpress plugins have depreciated code
such as
if ( count($this::$sources) > 0 ) Needs to be an array

and

list($post_type, $post_type_name) = each($types); each() no longer supported

Is there a tool that can run through a directory and at least identify lines of
code that would not work in php8.0 ?

And … ( BTW - how would I refactor the above for 8.0? )

Many thanks
Dave

Modifying plugin code is going to make it nearly impossible to update to new plugin versions.If you are going to to do that than it would be better to identify incompatibilities and possibly contribute fixes back to main repository so that those changes don’t result in branching off the main, managed plugin code. If you do it any other way you will either loose those changes when updating the plugin, not be able update, and/or introduce breaks. Managed dependencies like plugins belonging to Wordpress ecosystem in this case should not be hacked for the previously mentioned reasons. Doing so is going to create a miantainence nightmare.

While not the best solution, one solution I have used is to load your code into VS code and install an extension like Intellephense which has been doing a pretty decent job of catching some common PHP 8 deprecations/removals. On top of that, it will catch things which you might not be catching like unused variables, bad function calls etc.

It isn’t going to find everything, but it should catch many of the usual PHP 8 changes.

Are there your plugins?

If not: have you tried upgrading them?
If yes: try Rector.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.