Skip to content

RedundantCondition and superglobals when saved to variables #10474

Answered by robchett
natecraddock asked this question in Q&A
Discussion options

You must be logged in to vote

My understanding is that $_GET and $_POST would not be populated with null value, the closest being an '' in the case of ?value or ?value= hence the types being defined as they are.

In the second example isset is acting as an array_key_exists, not actually checking for a null value.
In the third the null coalesce provides the null value in the case of the key not existing and so it's doing the same thing as the second indirectly.

It's possible to set a value yourself which is null, but Psalm will report it at that point and continue to use the hinted type elsewhere. In this case Psalm is trying to provide safety for the 99%, and modifying superglobals is frowned upon

I don't think your wo…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@natecraddock
Comment options

Answer selected by natecraddock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants