Skip to content

Conversation

janedbal
Copy link
Contributor

@janedbal janedbal commented Jul 18, 2024

The failure happened here.


Generally, this feels like a trap inside PHPStan. If any ConstantArrayType will fail when used in implode or just with any usage of TypeUtils::flattenTypes, it is just not safe to create it by constructor and the degradation logic in ConstantArrayTypeBuilder should be imo moved to ConstantArrayType constructor.

Or maybe just getAllArrays needs to be fixed? IDK where is the proper place to fix this.

@ondrejmirtes
Copy link
Member

I feel like we should make a rule in PHPStan so that ConstantArrayTypeBuilder is used instead of new ConstantArrayType when the size of the created array is unknown. Because:

should be imo moved to ConstantArrayType constructor.

That's too late, you can't return a different type from a class constructor.

Otherwise I think this is the right fix. Thank you.

@ondrejmirtes ondrejmirtes merged commit ee88a01 into phpstan:1.4.x Aug 9, 2024
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants