Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
[TypeInfo] AddArrayShapeType
class#59827
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
3660bb4
toe1d1d9b
Compareforeach ($value as $key => $itemValue) { | ||
$valueType = $this->shape[$key]['type'] ?? false; | ||
if (!$valueType) { | ||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
For extra keys, the behavior is different betweenPHPStan (allow) andpsalm (restrict). You implemented the strict version:false
is returned when an extra key is present. This is consistent with psalm and PHPStorm 👍🏻
There is a syntax using...
to allow extra keys (demo); but this is not supported by PHPStorm and PHP_CodeSniffer.
/** @param array{foo: string, ...} $a */function fun(array$a):int
This feature can wait for a subsequent PR.
Thank you Mathias. |
cf5270c
intosymfony:7.3Uh oh!
There was an error while loading.Please reload this page.
This PR was merged into the 7.3 branch.Discussion----------[TypeInfo] Add `ArrayShapeType::$sealed`| Q | A| ------------- | ---| Branch? | 7.3| Bug fix? | no| New feature? | yes| Deprecations? | no| Issues || License | MITImplement sealed syntax for array shape type, as suggested in#59827 (comment).Commits-------fded1eb [TypeInfo] Add `ArrayShapeType::$extraKeyType` and `ArrayShapeType::$extraValueType`
This PR was merged into the 7.3 branch.Discussion----------[TypeInfo] Add `ArrayShapeType::$sealed`| Q | A| ------------- | ---| Branch? | 7.3| Bug fix? | no| New feature? | yes| Deprecations? | no| Issues || License | MITImplement sealed syntax for array shape type, as suggested insymfony/symfony#59827 (comment).Commits-------fded1eb5030 [TypeInfo] Add `ArrayShapeType::$extraKeyType` and `ArrayShapeType::$extraValueType`
Introduces the
ArrayShapeType
that holds the exact shape of an array. Also enables theStringTypeResolver
to parsearray{foo: int, bar?: string}
and to create the appropriate type.This PR needs#59824 to be merged first.