Skip to content

[WR] Support for nullable types in docblocks #329

Closed

Description

@Taluu

It seems that if I have a nullable property (?string, ?Foo, ... etc), it is marked as unknown instead of ?string and so on.

(I'm guessing it's a bug / missing feature on WR ?)

Activity

  1. changed the title [-]Support for nullable types[/-] [+][WR} Support for nullable types[/+] on Feb 19, 2018
  2. dantleech commented on Feb 19, 2018

    @dantleech
    Collaborator

    Yes, it is indeed. Should be relatively easy to implement.

  3. dantleech commented on Mar 1, 2018

    @dantleech
    Collaborator

    Do you mean @var ?string? I don't think that's standard: https://github.com/php-fig/fig-standards/blob/master/proposed/phpdoc.md#appendix-a-types

    Does PHPStorm support it? I would have expected @var string|null

    Also, don't think PHPStan supports that.

  4. Taluu commented on Mar 1, 2018

    @Taluu
    ContributorAuthor

    Didn't try with a @var or @param , but the nnullable typehint. And as it is a core feature of PHP 7.1, it would make sense to support it, nay ?

    The psr doesn't seem to have been updated for that.

  5. dantleech commented on Mar 1, 2018

    @dantleech
    Collaborator

    Hmm.. I only asked because its works for me: phpactor/worse-reflection@4558561

    Can you provide an example?

  6. Taluu commented on Mar 14, 2018

    @Taluu
    ContributorAuthor

    Yup, works on return type and typehint, but not on @param and @var. Even though it is not really documented in the psr (guess it's dead or something ?), it is still a valid php type, so it should IMO be supported.

  7. changed the title [-][WR} Support for nullable types[/-] [+][WR] Support for nullable types[/+] on Apr 1, 2018
  8. dantleech commented on Apr 6, 2018

    @dantleech
    Collaborator

    What's the use case for using this notation in a docblock? Supporting <7.1 code?

  9. changed the title [-][WR] Support for nullable types[/-] [+][WR] Support for nullable types in docblocks[/+] on Apr 6, 2018
  10. Taluu commented on Apr 6, 2018

    @Taluu
    ContributorAuthor

    I have an interface that can work on multiple (nullable) objects, and each implementation concerns a particular object. So I'm not typehinting anything (will change to ?object once we get to 7.2...), so I need to add a /** @param ?Foo $foo (or @var).

  11. weirdan commented on Jan 16, 2019

    @weirdan
    Contributor

    Also, don't think PHPStan supports that.

    PHPStan, Psalm and Phan support that notation.

  12. dantleech commented on Jan 19, 2020

    @dantleech
    Collaborator

    This should be "fixed" in #876 - it uses @var Type|null $foo by default, the .phpactor/templates/Property.php.twig could be overridden to use ? instad.

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

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions