Hey everyone,
I'm working on a PHP project and I'm facing a strange issue with PHPStan. It keeps reporting a possibly undefined variable, even though I have defined it in an included script.
So here's the situation:
I have a main script called `main.php` where I include another script called `helper.php` using the `require_once` statement. In `helper.php`, I define a variable called `$myVar` and assign it a value. Then, in `main.php`, I try to use that variable, but PHPStan keeps giving me the "possibly undefined variable" warning.
Here's the relevant code in `helper.php`:
```php
$myVar = 'Hello, World!';
```
And here's how I'm trying to use it in `main.php`:
```php
require_once 'helper.php';
echo $myVar;
```
I have made sure that both `main.php` and `helper.php` are in the same directory, so the file path is correct.
I'm really puzzled as to why PHPStan is flagging this variable as possibly undefined. Am I missing something here? Is there a specific way I should be including the `helper.php` file to ensure that PHPStan recognizes the variable?
I'd really appreciate any insights or suggestions you might have. Thanks in advance!

Hey there,
I've encountered a similar situation before, and I might be able to help you out. From my experience, PHPStan relies on static code analysis to infer variable definitions and usages. In some cases, it may not accurately recognize variables that are defined in included scripts.
To address this issue, you can try using the `@phpstan-ignore-next-line` annotation on the line where you're using the variable. This should tell PHPStan to skip the check for that particular line. However, please note that this is more of a workaround and not a recommended solution in general.
Alternatively, you can explicitly declare the variable as global in `main.php` using the `global` keyword. So, in `main.php`, you can add the following line before using `$myVar`:
This will ensure that PHPStan recognizes the variable as a global variable and removes the "possibly undefined variable" warning.
Give these approaches a try and see if they resolve the issue for you. Let me know if you have any further questions or if there's anything else I can assist you with. Good luck!