Skip to content

"Property does not accept" error when incrementing Array shapes #6333

@DaisukeDaisuke

Description

@DaisukeDaisuke

I am using google translate and deepl translate.
I apologize for the very long text of machine translation.

Bug report

When I increment the Array shapes of a class property that has more than one element, I get the following phpstan output:
Except for multidimensional arrays, it doesn't seem to occur if the initial values of the array shape are correctly assigned to the array.
Also, it does not occur when using array<>.

(from https://phpstan.org/r/1ccdd2ae-6def-45ba-8c01-c91c8f54ce8b)

Property HelloWorld::$test12 (array<int, array{value1: int, value2: int}>) does not accept array{array{value1: int}}.

Code snippet that reproduces the problem

class HelloWorld
{
    /**
     * @var array<string, array{stdClass, int}>
     */
    public array $detectedCheat = [];
    //If this function is actually executed, the php warning is obtained.   
    public function test(): void
    {
        $this->detectedCheat["playerName"][1]++;//error
    }
}

error

Property HelloWorld::$detectedCheat (array<string, array{stdClass, int}>) does not accept array{playerName: array{1: int}}.

https://phpstan.org/r/4f76a1f4-1e60-4d0e-a765-7f4ce90f2bcb

others codes(129 lines)

Property HelloWorld::$test11 (array{int, int}) does not accept default value of type array{}.
is not subject to this issuse.
https://phpstan.org/r/1ccdd2ae-6def-45ba-8c01-c91c8f54ce8b

Expected output

No error should occur.
Or, display undefined errors as needed.

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

Today phpstan reported where I forgot to refactor the program, saving me time to launch the program.

phpstan version

1.4.x-dev@b5e71db
phpstan/phpstan-src@b5e71db

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions