

We’ve also added an extra level of checking in cases where you both extend an (abstract) class and implement an interface. Here you can configure if comments count as being content or not, and if you want the inspection to fire on `foreach` and `while` loops.

You’ll find the settings for the inspection under Editor | Inspections | PHP | Probable bugs | Statement has empty body. A badly placed ` ` can make this a difficult bug to catch, even in code review. The new Statement has empty body inspection is designed to detect when you’ve added a conditional or loop statement but not included any code in the body of the statement. Inspections are really important for catching logical bugs where the code parses but things aren’t happening as you expected. You can turn it off if you don’t like it, you’ll find it under Editor | Inspections | PHP | Undefined | Undefined Field | Notify of dynamic field declaration.

Checking the constructor is particularly important given that’s traditionally where you’d initialise these fields, so being warned that properties are undeclared at this point is very useful. PhpStorm 2017.2 extends the existing inspections that detect when you use undefined fields by also checking in the constructor. Declaring properties is also slightly more memory conscious, because of the underlying way that PHP’s opcodes (the “compiled” version of the PHP text file you edit) store properties. PhpStorm 2017.2 introduces some nice new inspections to catch even more future bugs before they happen.ĭeclaring all properties you use in your PHP code is a good practice to ensure that you are using the property visibility you need, to catch bugs from typos, to improve type-hinting in PhpStorm using the annotation, and to make your code all around more readable. Inspections are the life-blood of PhpStorm, they are the little watchers that detect when you’ve done something suspicious (or even downright wrong) and pop up a little reminder saying “you may want to check that!”.
