Include files not respected in error reporting, how to fix?

I have various pages that link to other pages using the basic <?php require_once('connections/connection-file.php'); ?> that define variables used in connection queries. It's not a big deal but the variable generated in the include file is always flagged as an error for an 'undefined variable'.

Is there a setting that allows PHP Storm to recognize the content of included files to prevent these errors?


Hi there,

Yes, you need to configure that inspection to look for such a variable in other (require_once) files and not this file only (which is by default).

That "Undefined variable" inspection has the "Search for variable's definition outside the current file" option just for that.

1 "Settings/Preferences | Editor | Inspections"
2. "PHP | Undefined symbols | Undefined variable"
3. "Search for variable's definition outside the current file" <-- this option.


You can reach that option via the Settings/Preferences screen manually or do it faster right from the editor via Intentions/Quick Fix menu:


Wow, thank you Andriy, that solved the problem perfectly!


Please sign in to leave a comment.