Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array shapes handling gets broken when there are many keys (63?) #10080

Closed
ArtemGoutsoul opened this issue Nov 1, 2023 · 3 comments
Closed
Labels
Milestone

Comments

@ArtemGoutsoul
Copy link

ArtemGoutsoul commented Nov 1, 2023

Bug report

There's a array param with 63 keys (condensed code ):

<?php

/**
 * @param array{
 *    a1?: string,
 *    a2?: string,
 *    a3?: string,
 *  ....
 *    a59?: string,
 *    a60?: string,
 *    a61?: string,
 *    a62?: string|string[]|int|float,
 *    a63?: string
 * } $row
 */
function doStuff(array $row): void
{
	\PHPStan\dumpType($row['a51'] ?? ''); // Dumped type: string
	\PHPStan\dumpType($row['a51'] ?? ''); // Dumped type: array<string>|float|int|string
}

Not really sure what is happening here. If I remove any key - the problem goes away: i.e. the type shows up correctly as string for both lines.

Code snippet that reproduces the problem

https://phpstan.org/r/f79adf76-c8e5-46f9-8615-c887fa4324ea

Expected output

Dumped type: string
Dumped type: string

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

PHPStan makes me happy every day! :)

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Nov 1, 2023
@VincentLanglet
Copy link
Contributor

VincentLanglet commented Nov 2, 2023

For the record

It doesn't simplify the array, without the ?? ''
https://phpstan.org/r/efb9bc75-d1dc-4dc2-bbb3-7638bb1362c9

@ArtemGoutsoul
Copy link
Author

It doesn't simplify the array, without the ?? '' https://phpstan.org/r/efb9bc75-d1dc-4dc2-bbb3-7638bb1362c9

Without ?? it first says string which is partially true and then says Offset 'a51' does not exist on array... which is partially true.

It would be clearer if instead of both messages phpstan debug would report just one: Dumped type: string, offset 'a51' is optional in array..., but I'm not sure how complex this improvement would be.

@ondrejmirtes
Copy link
Member

Fixed phpstan/phpstan-src#3032

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants