Get Your Code PHP 7 Ready With PhpStorm 10

The release of PHP 7 is fast approaching, and there are some breaking changes that will need to be fixed to make sure your codebase is ready. Thankfully, PhpStorm 10 comes with a great inspection you can run to help you be prepared.

The PHP 7 Compatibility Inspection can show you exactly what code is going to cause errors if you are running PHP 7. It is enabled by default in PhpStorm 10.

PHP7 Readiness Inline

Here, you can see that the inspection has marked the class name Int because in PHP 7, int, string, float and bool have all become reserved words. This is useful when you’re working on a single file, but it’s inconceivable that you’ll open every file in your codebase to check there are no red squiggles.

Checking your whole codebase is actually easy, because you can manually run inspections against the scope of your choice. Simply select the Run Inspection By Name… option from the Code menu, and then select the PHP 7 Compatibility inspection. You’ll get asked which scope you’d like to run it on, and then see the results from the inspection in the results pane.

PHP7 Readiness ResultsHere, you can see that there are a number of validator classes that get bundled with Zend Framework 2 and have names of words that will be reserved in PHP 7. Now we know exactly what we need to fix so we can be prepared when PHP 7 gets released at the end of November.

Keep up with the latest PhpStorm news on our blog and follow us on Twitter @phpstorm.

Develop with pleasure!
– JetBrains PhpStorm Team


About Gary Hockin

Gary Hockin has been creating code to power web applications for 15 years, the last three of them at an extraordinary level. He is handsome, talented, funny and articulate, and also extremely modest. Gary is a valued contributor to Zend Framework 2 and is a member of the community review team. He's married and has two wonderful children, and when he's not coding, writing about code, speaking about code or reading about code, he can usually be found in the pub playing pool.
This entry was posted in Cool Feature, PhpStorm and tagged , . Bookmark the permalink.
  • Michael Yoo

    Is there any other feature regarding PHP 7 Readiness Inspection apart from keyword blacklisting 7 words…?

  • Carsten Windler

    This looks really promising! However I agree with Michael Yoo – is there some page which gives us more information what checks are actually performed?

    I’m very concerned about changes in the semantics when using variable variables/properties, e.g. $obj->$properties[‘name’]. Would the inspection throw at least warnings here?

    • Anna Lebedeva

      Currently implemented detection of the following errors:
      -class declarations with names int, string, bool, float
      -usage of more than one default case in switch
      – detection of forbidden use alias name
      – API changes will be covered by separate inspection that will check @since & @deprecated versions vs current language level

  • Keith Davis

    I don’t an Inspection named “PHP 7 Readiness Inspection”, I see one called PHP 7 Compatibility.

    • Keith Davis

      Ok, I just saw that directions to Run Inspection by Name, but that does not work either.

      • Anna Lebedeva

        We renamed “PHP 7 Readiness Inspection” to “PHP 7 Compatibility Inspection” in the latest PhpStorm version. Thanks for pointing it out! We will update the blog post to avoid further misunderstanding.

  • Kris Spencer

    Inspection does not appear to detect required variable AST changes. Here is an example of a line of code that works fine in PHP5.6 but should give an array to string conversion exception in PHP7 (and was not detected by the inspection).

    $my_obj->$this_row[‘id’]->id = $this_row[‘id’];

    fixed for PHP7, it will become:

    $my_obj->{$this_row[‘id’]}->id = $this_row[‘id’];

    Hope this helps,

  • Dmitry Tronin

    For anyone interested: this inspection is merged into PHP | General | Language Level inspection.