Skip to content

Invalid return type definition #10786

Closed
phpstan/phpstan-src
#6131

Description

@yurybykov

Bug report

Invalid return type definition (check example), but all variables checks are present.
Found 1 error: "Method HelloWorld::sayHello() should return int but returns int|null."

Code snippet that reproduces the problem

https://phpstan.org/r/a66a0cf3-2a04-4b26-be2d-39c1953726a7

Expected output

No error.

Did PHPStan help you today? Did it make you happy in any way?

No response

Activity

  1. added this to the Dependent types milestone on Mar 26, 2024
  2. ondrejmirtes commented on Mar 26, 2024

    @ondrejmirtes
    Member

    We already have this working for variables: https://phpstan.org/r/b22a51ff-14f5-483f-871a-10d319052b15

    So it's "just" a matter of making this work for general expressions. The relevant piece of code is where we work with ConditionalExpressionHolder.

  3. EdwinHuijsing commented on Apr 4, 2026

    @EdwinHuijsing

    Here is an other example with the same problem
    https://phpstan.org/r/68d94256-0329-45bc-b48a-8bfc32fb956e

    strtotime is check and returns a no false value, but still a error is shown that int|flase is returned
    Method CoffeeBreak::example() should return int but returns int|false.

  4. ondrejmirtes commented on Apr 4, 2026

    @ondrejmirtes
    Member

    @EdwinHuijsing This code is incredibly wasteful. You should call strtotime once, save the result into a variable and have the variables guarded and returned. PHPStan won't complain about it either.

  5. added a commit that references this issue on Apr 4, 2026
    5054450
  6. github-actions commented on Aug 29, 2026

    @github-actions

    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.

  7. locked as resolved and limited conversation to collaborators on Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions