phpstan: Wrong return type in ternary operator

Bug report

Stan seems can not derive correct type if ternary operator used like this: $test->test() ? $test->test()->format('d') : null

Code snippet that reproduces the problem

https://phpstan.org/r/ff44c8c8-06ca-470a-a716-ebd334aee215

Expected output

Stan should not complain about type.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 22 (20 by maintainers)

Commits related to this issue

Most upvoted comments

Yeah, I plan to do something about it, stay tuned.

But please stop discussing this in this issue, it’s unrelated.

json_decode return type is mixed so it can return anything, but it also might return the correct thing. That’s why it doesn’t complain. And it’s unrelated to this issue.