-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
Allow null
and false
as standalone types
#7546
Conversation
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.
The implementation looks good but I had some nits on test cases.
Being able to indicate something is always null would save the need to add redundant @return null
phpdoc (and assert that all subclasses (e.g. from mocking libraries) also return null).
It would also allow type checkers such as Phan/Psalm/PHPStan to more aggressively warn about unnecessarily using the return value, impossible type checks, etc.
--FILE-- | ||
<?php | ||
|
||
function test1(): null|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.
nit: Would be useful and help readability to call these and test the expected behavior, and have example implementations where return null;
is properly included in the implementation.
Readers of the RFC might be looking at the tests to see how it's used
Warning: Uncaught TypeError: Return value of test1() must be of the type false or null, none returned....
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.
I'll add such a test case
Regarding the motivation: "However, the opposite isn't true, if the child method returns always null it must still use the original function signature and can only provide this information through documentation. " - and why exactly is this important? What are the real world proper examples that care if child method returns strictly null or not? "The inability to type the unit type in PHP is a deficiency which should be resolved. " - again, why should it be resolved? What's the reasoning? You can't type "true" either, there aren't any literal types except for "false". And imho, that's a good thing. |
Hi @autaut03 PRs discussions are for detailed technical aspects of the code in the PR. Wider discussions of the RFC being good or bad should be on the internals mailing list. |
0480a0e
to
cb0a96b
Compare
null
and false
as standalone types
7936168
to
1041d2a
Compare
1041d2a
to
ee1b290
Compare
…n type on PHP 8.2 (alexandre-daubois) This PR was merged into the 4.4 branch. Discussion ---------- [Serializer][PropertyInfo] Fix support for "false" built-in type on PHP 8.2 | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes (new language feature support) | New feature? | no | Deprecations? | no | Tickets | _NA_ | License | MIT | Doc PR | _NA_ `false` and `null` built-in types have been merged in PHP 8.2 a few hours ago: php/php-src#7546 🎉 RFC: https://wiki.php.net/rfc/null-false-standalone-types PropertyInfo and Serializer both need an update to support them. Commits ------- 4187d3f [Serializer][PropertyInfo] Fix support for "false" built-in type on PHP 8.2
…n type on PHP 8.2 (alexandre-daubois) This PR was merged into the 4.4 branch. Discussion ---------- [Serializer][PropertyInfo] Fix support for "false" built-in type on PHP 8.2 | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes (new language feature support) | New feature? | no | Deprecations? | no | Tickets | _NA_ | License | MIT | Doc PR | _NA_ `false` and `null` built-in types have been merged in PHP 8.2 a few hours ago: php/php-src#7546 🎉 RFC: https://wiki.php.net/rfc/null-false-standalone-types PropertyInfo and Serializer both need an update to support them. Commits ------- 4187d3fddd [Serializer][PropertyInfo] Fix support for "false" built-in type on PHP 8.2
RFC: https://wiki.php.net/rfc/null-standalone-type
Also a drive-by consistency fix for error messages.