phptools-docs
phptools-docs copied to clipboard
No error for using undefined variable if previously referenced in unrelated `empty()` check
In this code:
I understand why the first and second references to $avar are not highlighted as errors, but the last one should be.
The fact that I've called empty() on it previously is irrelevant. You can't just assume that because I thought about it once I'm not forgetting to do the same again.
Even more absurd:
You are correctly highlighting it as error inside the if block, but then, you're still failing to highlight the last occurrence.
If I remove the call to empty() then it's highlighted as expected:
Yes, the empty check overrides everything we think we know about that variable and the result is not helpful.
Regarding the error, we underlined the first occurrence only for simplicity.
Regarding the error, we underlined the first occurrence only for simplicity.
Normally that's not the case when empty() is not interfering.
Example 1:
Example 2:
And these are basically like the examples in the original report: