PHPStorm recognizing variable not included in PHP file

Hi guys!

I'm having this issue where PHPStorm is recognizing a  variable name as valid (and even suggesting it to me with code  completion), even though that variable is not declared in the script  file or included from another file.

Here's how to reproduce it:

1) Create a new empty project.

2) Create a PHP file named a.php with the following contents:

<?php $customerName = 'Mary';


3) Create a second PHP file named b.php with the following contents:

<?php echo $customerName;


4) Check if PHPStorm inspection fails for b.php (which is what should happen here).

Since a.php is not included in b.php, I think that b.php should not know about variable $customerName, right?


The interpreter will not print the customer name and will report a warning.


Shouldn't PHPStorm inspection for undefined variables do the same?


Attachment(s):
example.png

Please sign in to leave a comment.