-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[POC][RFC] Nullable Casting (and settype()) #3764
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
[POC][RFC] Nullable Casting (and settype()) #3764
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 Zend/tests/cast_to_array-nullable.phpt
test is been considering as a new Binary file for some reason
@carusogabriel This is expected. It's because the file contains some NUL character (in the
--EXPECTF-- section, output of a var_dump() of "\0" ). GitHub does not show the contents in its diff view but you can click the "View file" button: at line 67 I see string(1) "" but there is actually an invisible NUL between the quotes (see e.g. https://3v4l.org/luX7q, and also https://3v4l.org/j1Q3D).
It was copied as-is from the existing (BTW there is a trailing space in |
Update: the RFC is now under discussion on internals@: https://externals.io/message/105122 |
FWIW re-reading that internals thread, the reception is somewhat mixed, but I think it still makes sense to put the RFC to voting. |
@nikic: Thanks for your time. But now we have union types (which I consider much more important than nullable casting, by the way!), so people will probably want the RFC to include the Anyway I didn't (and won't) have the time to keep this PR up to date, so it wasn't really making sense to let it open... |
@guilliamxavier casting with union types seems a bit confuses and restrict. For instance, So I still thinks that nullable casting will works better and will match with an existing feature like typed properties and parameters. |
@rentalhost: Casting is only to primitive types, so |
Good point about the union types. There could indeed be a reasonable expectation that once If we had generics (haha), we could do a C++ style cast that would automatically support all types and have the same semantics as weak type coercions:
|
@guilliamxavier do you think it could be happen at 8.0? |
@rentalhost: unlikely, given the lack of consensus (and the increasing divergence of type declarations [now with union types] vs casts [fixed tokens])... But actually I find nikic's idea more promising |
Just trying to initiate some movement for https://wiki.php.net/rfc/nullable-casting (including
settype()
as requested in https://externals.io/message/102997#102999) 🙂/cc @rentalhost (author of the RFC)
I made some choices open to discussion, for example not supporting
(?unset)
at all but allowingsettype($x, '?null')
with a notice (which I found simpler for a start).The new tests are essentially minimally-modified copies of existing ones.
Questions:
T_NULLABLE_<TYPE>_CAST
token for eachT_<TYPE>_CAST
(exceptT_UNSET_CAST
) like I did, the "right" way?ZEND_AST_NULLABLE_CAST
" node and/or a new "ZEND_NULLABLE_CAST
" opcode be better than extending the existingZEND_AST_CAST
andZEND_CAST
with theZEND_TYPE_NULLABLE
flag like I did?