Skip to content

Creating new array on mixed[] should be allowed if key does not exist. #6209

@biozshock

Description

@biozshock

Bug report

mixed[] type actually allows to have a multidimensional array if the key is not set.

Code snippet that reproduces the problem

/**
 * @param mixed[] $values
 * @return mixed[]
 */
function apply(array $values): array
{
	if (!array_key_exists('key', $values)) {
		$values['key'][] = 'any';
	}
	
	return $values;
}

https://phpstan.org/r/587e0c33-7144-4bcc-aa96-e284d2a53ab3

Expected output

No error.

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

Thanks all involved people for such a great tool. Especially for this latest one i've got!
https://phpstan.org/r/3d7adc9b-8ea4-4cd8-bada-b5117e57211d

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions