Is there any way in PHP to do static code analysis and detect reliance on the register_globals initiative? It’s relatively straightforward to manually examine a file and look for variables which have not been initialized and infer from that that these may be relying on it, but I need to do this for many hundreds of scripts, so I’m looking for an automated solution.
My last resort is setting up a dev environment with the directive turned off and strict error reporting and letting QA play around for a long while, then fix the instances that the error log catches, but this is not guaranteed to find 100% of the cases, and certainly not a good use of resources if an automated solution exists.
A small script I just hacked together to detect simple undefined variables. You’ll need PHP-Parser for this:
It’s just a very basic implementation and I did not test it extensively, but it should work for scripts that don’t go wild with
$GLOBALSand$$varVars. It does basic include resolution.