Add support for Psl\Type\nullish() in shape types#31
Merged
ondrejmirtes merged 3 commits intophp-standard-library:2.0.xfrom Mar 17, 2026
Merged
Add support for Psl\Type\nullish() in shape types#31ondrejmirtes merged 3 commits intophp-standard-library:2.0.xfrom
ondrejmirtes merged 3 commits intophp-standard-library:2.0.xfrom
Conversation
Nullish wraps a type as T|null while keeping the key required, unlike optional() which makes the key absent. Supports both standalone nullish(T) and combined optional(nullish(T)).
veewee
commented
Mar 16, 2026
- Use string literal instead of NullishType::class to avoid class-not-found errors on PSL versions without NullishType - Move nullish tests to separate fixtures, gated by class_exists() - Add PHP 8.2, 8.3, 8.4, 8.5 to CI matrix
- Restore NullishType::class instead of string literal - Add baseline ignores for older PSL versions without NullishType - Fix CS: add use statements for NullishType and class_exists in test
Collaborator
|
Thank you. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Psl\Type\nullish()support for shape type inference, wherenullish(T)produces a required key with typeT|nulloptional(nullish(T))producing an optional key with typeT|nullNullishTypeandnullish()function, mirroring the existingOptionalType/optional()patternAligns with azjezz/psl#618, mago#1391, and psalm-plugin#18.
Test plan
nullish(string())in shape →array{bio: string|null}(required, nullable)optional(nullish(string()))in shape →array{bio?: string|null}(optional, nullable)