Skip to content

False positive Static property HelloWorld::$bug (WeakMap<stdClass, stdClass>) does not accept WeakMap<object, mixed>. #5551

@LastDragon-ru

Description

@LastDragon-ru

Bug report

When you do something like phpstan will report "Static property HelloWorld::$bug (WeakMap<stdClass, stdClass>) does not accept WeakMap<object, mixed>", probably it must not do this (non-static property work as expected).

class HelloWorld
{
    /**
     * @var WeakMap<\stdClass,\stdClass>
     */
    protected static WeakMap $bug;

    public function bug(): void
    {
        static::$bug = new WeakMap();
    }
}
name     : phpstan/phpstan
descrip. : PHPStan - PHP Static Analysis Tool
keywords :
versions : * 0.12.96
type     : library
license  : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText
homepage :
source   : [git] https://github.com/phpstan/phpstan.git a98bdc51318f20fcae8c953d266f81a70254917f
dist     : [zip] https://api.github.com/repos/phpstan/phpstan/zipball/a98bdc51318f20fcae8c953d266f81a70254917f a98bdc51318f20fcae8c953d266f81a70254917f
path     : /project/vendor/phpstan/phpstan
names    : phpstan/phpstan

Code snippet that reproduces the problem

https://phpstan.org/r/c82951da-ead5-4999-a670-db23e6fb07b3

Expected output

no error

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

Yep, it is found one possible bug today.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions