Ancient code "passes" PHP7 Compatibility inspection - ha!
I'm gearing up to refactor a really old project (currently running on PHP 5.2.something) to run on PHP7. I read here that PHPStorm has a compatibility checker, so I followed the instructions:
- From the menu I selected Code -> Run Inspection by Name...
- I typed "PHP7" and selected "PHP7 Compatibility".
- With Inspection Scope set to "Whole project", I clicked OK.
It took a few seconds and then reported: "No suspicious code found. 160 files processed in 'Project 'name of my project.'' Right! For starters, I know my code is littered with mysql_[various]() calls, so that's a bald-faced lie. Why does the PHP7 Compatibility Inspection not find anything? Am I calling it wrong or need some sort of reference file I don't have? I recently installed version 2016.3.
请先登录再写评论。
Hi there,
I think it has to do with the fact that deprecated/no-longer-available functions and classes is a different story to actual language constructs/syntax/keywords.
IDE can check language constructs/syntax based on the Language Level (when you setting up PHP Interpreter). And this is what this inspection (compatibility checked) checks for. It can also check for unacceptable class names/namespaces and alike.
But deprecated/no-longer-available functions and classes .. or missing/new function parameters or constants and alike .. it's a matter of stubs .. which at the moment are one for all PHP versions. Basically, stubs are not properly versioned yet. https://youtrack.jetbrains.com/issue/WI-16509
I think they could have added mysql_* functions (and other no-longer-available-for-sure) to that hard-coded class/namespace list as well. Why it was not done? My only guess -- they possibly expected that the aforementioned ticket would be resolved by then ... or left it for later...
Right now you may run "Deprecated" inspection separately -- but it will include all mentions of functions/classes/ect where `@deprecated` tag is used in their PHPDocs (be it PHP Core functions .. or framework you are using .. or your own code)
Thanks. Bummer about the stubs, but thanks for explaining. The Deprecated" inspection did list the mysql_* calls, but I was hoping for a tool that would show me the problems I'm NOT already aware of and/or that can't be found with a simple search.
Just now I tried https://github.com/Alexia/php7mar, but it also only reported the mysql_* calls as "critical". I find it hard to believe that those are the only things that would break in this code, some of which is 10-15 years old. But I'll fix them and see.