Skip to content

Incorrect type interpretation #16524

@johnkhansrc

Description

@johnkhansrc

Description

The following code:

<?php
    /**
     * @return array<string, string>
     */
    public function dict(): array
    {
        return [
            'foo' => 'bar',
            '1' => '1 year',
            '2' => '2 years',
            '3' => '3 years',
            '4' => '4 years',
            '5' => '5 years',
        ];
    }
?>

Resulted in this output (static warning):

should return array<string, string> but returns array<int|string, string>

But I expected this output instead:

array<string, string>

PHP Version

PHP8.3

Operating System

Ubuntu 24.01

As I am not sure that this comes from the interpreter I also published the issue on the static analysis tool repo (phpstan) : phpstan/phpstan#11880

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