Features Releases

Project Wide PHP 7 Strict Types in PhpStorm 2016.3

PHP 7 is here, and thankfully gaining a lot of traction. There’s never been a better time to convert your project to PHP 7 strict types, and you’ll find so many bugs you never knew existed in the process. Adding the strict types declaration to all of those files can be painful, and you may forget some places. PhpStorm 2016.3 has got you covered.

PhpStorm 2016.3 has introduced a new inspection, the Strict types declaration setting that you can find under Type compatibility in the Inspections pane of the Preferences window.

2016-3-strict-typesOnce you enable this inspection, any files missing the strict type declaration will get a warning on the first line at the opening `<?php` tag.

2016-3-strict-types-2

As with any of the inspections, you can also run across the whole (or parts) of your project by using the Run Inspection by Name option in the Code menu, then selecting the scope you wish to run the inspection on.

2016-3-strict-types-3

You can see here we have 68 files that are missing the declaration. Thankfully, PhpStorm 2016.3 also ships with an intention that can fix the problem, and add the statement to the top of the file. You can either do this in batch across all found files by clicking the Add strict types declaration button, or on a case by case basis in each file by firing the Show Intentions selector (default keybinding of Alt+Enter) and selecting Add strict type declaration.

https://youtu.be/NWsTZn_b-MU

Adding strict type hinting to your PHP projects just got a lot easier. Give it a go and let us know what you think.

– Gary and the PhpStorm Team

image description