You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After upgrading to the latest version, I noticed that there is a new error which doesn't make sense to me as the variable is an array and is not mixed. I assume it might be because it's global which could have been changed, but in the example linked the global does not change nor could it change. The line before the problem line validates that it is an array.
PHPStan does not goes down into getDisplay implémentation.
But it doesn't need to go down into getDisplay. The variable cannot be mixed either way. For it to change from array to mixed it would need to change between $_SESSION['Import_message']['message'] and $_SESSION['Import_message']['go_back_url'], i.e. after the call to getDisplay.
ohh I missed that the super-global variable type is invalidated because of the getDisplay-method purity not beeing defined.
Vincent is correct. PHPStan is pessimistic about the method beeing called could fiddle with the super-global.
you can use @phpstan-pure as Vincent suggested to tell PHPStan that the method will not change global state.
Vincent is correct. PHPStan is pessimistic about the method beeing called could fiddle with the super-global.
you can use @phpstan-pure as Vincent suggested to tell PHPStan that the method will not change global state.
Isn't it a bit too pessimistic though? Or to put it differently, why does it complain about the next line instead of the one that assigns the result of the method call? If the global variable was fiddled with then the assignment $_SESSION['Import_message']['message'] will fail. If this assignment cannot fail, then the next line for sure cannot fail.
Vincent is correct. PHPStan is pessimistic about the method beeing called could fiddle with the super-global.
you can use @phpstan-pure as Vincent suggested to tell PHPStan that the method will not change global state.
Isn't it a bit too pessimistic though? Or to put it differently, why does it complain about the next line instead of the one that assigns the result of the method call? If the global variable was fiddled with then the assignment $_SESSION['Import_message']['message'] will fail. If this assignment cannot fail, then the next line for sure cannot fail.
I agree with this, that's why I didn't immediatly close the issue you might consider reopening it @staabm ?
Anyway it will be faster/easier for you to rewrite your code @kamil-tekiela for now.
Activity
VincentLanglet commentedon Jul 27, 2026
PHPStan does not goes down into getDisplay implémentation.
You have multiple fixes
kamil-tekiela commentedon Jul 27, 2026
But it doesn't need to go down into
getDisplay. The variable cannot be mixed either way. For it to change from array to mixed it would need to change between$_SESSION['Import_message']['message']and$_SESSION['Import_message']['go_back_url'], i.e. after the call togetDisplay.staabm commentedon Jul 27, 2026
ohh I missed that the super-global variable type is invalidated because of the
getDisplay-method purity not beeing defined.Vincent is correct. PHPStan is pessimistic about the method beeing called could fiddle with the super-global.
you can use
@phpstan-pureas Vincent suggested to tell PHPStan that the method will not change global state.another fix would be using a local array and write into the super-global only once:
https://phpstan.org/r/d9565e4a-dbce-45fa-96f7-a0d3f631eef9
kamil-tekiela commentedon Jul 27, 2026
Isn't it a bit too pessimistic though? Or to put it differently, why does it complain about the next line instead of the one that assigns the result of the method call? If the global variable was fiddled with then the assignment
$_SESSION['Import_message']['message']will fail. If this assignment cannot fail, then the next line for sure cannot fail.Failing: https://3v4l.org/skmuD#v
Ok: https://3v4l.org/YTm4I#v
More accurate examples:
Failing: https://3v4l.org/MFaSp#v & https://phpstan.org/r/60873521-9ff4-45e3-ba18-42b792592787
Ok: https://3v4l.org/MjsCr#v & https://phpstan.org/r/0a80a4e5-b356-442b-8340-75a8de044ae5
VincentLanglet commentedon Jul 27, 2026
I agree with this, that's why I didn't immediatly close the issue you might consider reopening it @staabm ?
Anyway it will be faster/easier for you to rewrite your code @kamil-tekiela for now.
staabm commentedon Jul 27, 2026
global variables can have all types of ugly side-effects we cannot forsee.
of course we can re-open this issue. @VincentLanglet how would you image a possible improvement/solution for the given scenario?
VincentLanglet commentedon Jul 27, 2026
Technically we should report the error on the line
and not the following one. (see https://3v4l.org/MFaSp#v)
$message->getDisplay()seems to invalidate$_SESSIONtoo late actuallystaabm commentedon Jul 27, 2026
strictly speaking you are right. I don't think we should spent time on this edge-case though.
Add regression tests for #14999 and #13334
Add regression tests for #14999 and #13334
Add regression tests for #14999 and #13334
Add regression tests for #14999 and #13334
Add regression tests for #14999 and #13334
Add regression tests for #14999 and #13334
Add regression tests for #14999 and #13334
Add regression tests for #14999 and #13334
github-actions commentedon Oct 4, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.