Skip to content

Why does not defining array key type end up as mixed type? #8301

@soyuka

Description

@soyuka

Discussed in #7749

Originally posted by balintcodes February 11, 2026
Hi there,

After a version bump of dependencies in a Symfony project I noticed that since December symfony/type-info throws an InvalidArgumentException when it faces a mixed key type (see update here).

I ended up at ApiPlatform\Metadata\Util\PropertyInfoToTypeInfoHelper::createTypeFromLegacyValues(). At some point it does the following:

$variableTypes[] = \is_array($collectionKeyTypes) ? Type::mixed() : Type::union(Type::int(), Type::string()); // @phpstan-ignore-line

Because of this, PHPDoc annotations like so throw an error in entities:

/*
 *@return array<string>
 */
private array $foo = [];

Can anyone help me wrap my head around why this is, and if I understand it right, why a mixed type is returned in every scenario, since $collectionKeyTypes is always an array?
Fixing such annotations in now a big deal, I'm more interesed in the whys:)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions