-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Nullable types #1893
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
Nullable types #1893
Conversation
Correct me if I'm wrong, but I don't think the tests currently check for the interaction between |
Indeed, I haven't added tests for this part. Will look into it later. |
The RFC has some potential test-cases, I guess: https://wiki.php.net/rfc/nullable_types#default_values |
The patch misses inherited method compatibility rules described in RFC. |
I have spot checked method compatibility and didn't see any issue with the patch. Can you provide examples for both situations, @dstogov? |
See the second example from https://wiki.php.net/rfc/nullable_types#parameters From: Levi Morrison notifications@github.com I have spot checked method compatibility and didn't see any issue with the patch. Can you provide examples for both situations, @dstogovhttps://github.com/dstogov? You are receiving this because you were mentioned. |
I see an issue with the formatting in the error string but the behavior looks to be correct. Where is the backwards compatibility break? |
You propose to disable overriding nullable with non-nullable, so the following code (from your email) won't work any more (it works in 7.0). From: Levi Morrison notifications@github.com I see an issue with the formatting in the error string but the behavior looks to be correct. Where is the backwards compatibility break? You are receiving this because you were mentioned. |
Oh, I see - Bob just silently reintroduced the BC break bypassing the RFC [😊] I reverted this. This break is actually a part of your RFC. From: Dmitry Stogov You propose to disable overriding nullable with non-nullable, so the following code (from your email) won't work any more (it works in 7.0). From: Levi Morrison notifications@github.com I see an issue with the formatting in the error string but the behavior looks to be correct. Where is the backwards compatibility break? — |
I'm surprised that example works in 7.0 at all, it seems like an LSP violation. |
Dmitry, The following code fails with an error since PHP 5.3+ (https://3v4l.org/kRKUN): interface Fooable {
function foo(Fooable $f = null);
}
interface StrictFoo extends Fooable {
function foo(Fooable $f);
} Thus this is not a BC break: interface Fooable {
function foo(?Fooable $f);
}
interface StrictFoo extends Fooable {
function foo(Fooable $f);
} The BC break you are thinking of has to do with changing the default parameter in this subclass so it isn't null anymore. That has to do with default parameters, not nullable parameters, and is therefore not part of this RFC. Does that make sense? |
0759661
to
e670226
Compare
Sorry, I'm far from computers till Wednesday. The example I sent you works on PHP 7.0.5. -------- Original Message -------- Dmitry, The following code fails with an error since PHP 5.3+ (https://3v4l.org/kRKUN): interface Fooable { Thus this is not a BC break: interface Fooable { The BC break you are thinking of has to do with changing the default parameter in this subclass so it isn't null anymore. That has to do with default parameters, not nullable parameters, and is therefore not part of this RFC. Does that make sense? You are receiving this because you were mentioned. |
e670226
to
a5a7e90
Compare
This works off of Dmitry's commit for nullable return types
This also affects bug #72119
a5a7e90
to
56c3d75
Compare
Hi, (function (?int $x) {})();
// Fatal error: Uncaught TypeError: Argument 1 passed to {closure}() must be of the type integer, none given (function () : ?bool {})();
// Fatal error: Uncaught TypeError: Return value of {closure}() must be of the type boolean, |
Good point. From: Michael Moravec notifications@github.com Hi, (function (?int $x) {})(); (function () : ?bool {})(); You are receiving this because you were mentioned. |
Perhaps it could say "must be either null or of the type integer", or even "must be either of the type null or of the type integer". |
I would change the error message from "must be of the type X" to "must be of the type X or null" From: Andrea Faulds notifications@github.com Perhaps it could say "must be either null or of the type integer", or even "must be either of the type null or of the type integer". You are receiving this because you were mentioned. |
Shouldn't there be a test to ensure that the following is not allowed? function nullableVoid(): ?void {} |
How about:
Imho @theodorejb: And maybe also nullable null ( |
|
Reverting a change made by a previously accepted RFC could be quite controversial. You might want to make a separate RFC for that. |
This is an implementation for the Nullable Types RFC.