Undefined Variable/Show Usages if set in IF statements?
I'm all for learning proper coding standards, and I clearly must be doing things unconventionally, but if I set a variable inside an if statement, in fileA.php and then require fileA.php and echo $setVariable, I get undefined variable. If I move the $setVariable outside of the if statement, it works fine.
I guess (might be asking TOO much), that Show Usages literally knows everywhere you've called $setVariable and it would show... all usages.
Use-case:
init.php - Check if session is set, and sets additional variables if so.
home.php - Requires init.php, and then further down echo $setVariableA shows undefined, AND Show Usages doesn't show $setVariableA = //things in init.php. It's like PhpStorm literally knows nothing about the $setVariableA in init.php if it's set inside the IF statement. Now, I can see an argument for making null variables set outside of the if statement, but that seems even more improper just so I can get PhpStorm to "work" per se.
Am I doing something wrong?
请先登录再写评论。
Could you please attach files/code parts you're working with to avoid any misunderstanding?
config.php
if ($_SESSION) {
$var = "set";
}
index.php
Ctrl-Click on $clientCompanyName says the isset is the only usage.
If I do:
config.php
index.php
Then Ctrl-Click takes me to the empty variable in config.php.
So it looks like PhpStorm doesn't read variables inside IF conditions? I somewhat get that, but it knows what's in all files of the project, it still should know that $clientCompanyName is contained in config.php.