Skip to content

Error on using nullsafe property access on empty array #4688

Discussion options

You must be logged in to vote

Consider this: https://3v4l.org/WB2UW You're getting a warning for accessing an undefined array key. The ?-> operator should only save you from getting "calling method on null": https://3v4l.org/Bsuoc (still getting a warning)

It's a bit messy because you're not getting the warning thanks to ?? operator afterwards: https://3v4l.org/jdNaC

I'd say that in this situation, code that uses just -> works identically: https://3v4l.org/paRS1

So PHPStan's error "Using nullsafe property access on non-nullable type stdClass. Use -> instead." is actually correct I'd say. WDYT?

Replies: 1 comment 1 reply

Comment options

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

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