Skip to content

Templated static properties should not be allowed. #11599

Open

Description

@DaveLiddament

Bug report

I don't think it should be possible to use templates for static properties.

See Java's reasoning: section Cannot Declare Static Fields Whose Types are Type Parameters on this page

Code snippet that reproduces the problem

https://phpstan.org/r/44079bf9-e167-4e2e-bdea-fd9dfb81253d

Expected output

I'd expect an error on line 10, something like: Static properties can not be templated.

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

PHPStan makes PHP a dream to code with. I really love the ability to create custom rules. Thanks for all your work.

Activity

  1. added this to the Generics milestone on Aug 31, 2024
  2. ondrejmirtes commented on Aug 31, 2024

    @ondrejmirtes
    Member

    There was an attempt to do this for both properties and methods: phpstan/phpstan-src#2232

    We might be able to do it just for properties and not break any weird real-world scenarios (there are weird scenarios for methods), but for properties the current API of FileTypeMapper doesn't allow it :/

    It'd be easier to have a new rule to point it out in static properties, instead of changing the engine to ignore @template altogether.

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