Skip to content

PHPStan assumes function/method returns value even if it can throw an exception #3710

@DaveLiddament

Description

@DaveLiddament

Bug report

Referring the the code snippet... It appears that PHPStan assumes that $person is always set. Given the method createPersonButCouldFail can throw an exception (and is annotated with @throws), this will not always be the case.

Code snippet that reproduces the problem

https://phpstan.org/r/671b1297-7856-4edf-871f-8f9e1d4f7169

Expected output

Expect 2 outcomes:

  1. Issue currently reported on line 22 (If condition is always true) is not reported
  2. An issue is reported on line 27 (Cannot call method aMethod() on Person|null.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions