-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Implement typed properties #3734
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
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.
@nikic From the tests part, just a couple of tests, for example, Zend/tests/type_declarations/typed_properties_019.phpt
, that have a fell extra lines at the end of the lines. I'll run this implementation in some OSS projects, see if I can found some missing tests 👍
@carusogabriel I've added some basic property type support to https://github.com/nikic/TypeUtil for this purpose. For now I've only tested that PHP-Parser works after automatically annotating it with property types (needs some manual fixup to fix inaccurate |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
RFC: https://wiki.php.net/rfc/typed_properties_v2 Co-authored-by: Bob Weinand <bobwei9@hotmail.com> Co-authored-by: Joe Watkins <krakjoe@php.net> Co-authored-by: Dmitry Stogov <dmitry@zend.com>
Add two more macros ZEND_TRY_ASSIGN_VALUE and ZEND_TRY_ASSIGN_COPY to assign zvals and replace all remaining uses of the internal API. Switch the API to not use a temporary zval anymore, as all users of the API take care to do this themselves.
I found the 1+count here much more confusing than helpful.
That's what it does...
And add tests for typed properties + references + undefined classes. I think the behavior here is not correct and we should treat this the same way we do elsewhere (if the class can't be loaded, conclude that it can't be an instance of the class, but don't issue an error). Going back to this behavior for now to avoid an assertion failure...
This is probably going to need changes in a few more places that currently implicitly assume only CE types can occur.
If the value_type is not known at compile-time, don't perform checks for whether the copy is needed or not, always do it. Also make sure we free the copy in the error case...
If we're in a class that has type hints, actually seeing a type is not unexpected.
This makes it consistent with the function for ref types and avoids having to handle these differently.
And remove some code handling future possibilities where a property could be both int and double. I don't like having untestable code around. Let's deal with this fully once we have union types.
And remove some redundant checks.
Made a mistake here when refactoring the code, causing a failure in serialization test.
Based on the descision that we do not want to enforce __get() return types for inaccessible propreties.
It's not relevant in any other case and might be wrong wrt cache state I think.
We have the proprerty offset here and know it's valid, so we can use our property helper table to fetch it, rather than doing a full property info lookup.
By switching to the slot API, which doesn't need unmangled keys and is faster anyway... Also moving those APIs to a place that has a complete prop_info def.
I originall thought this wasn't possible, but now that it turned out that object_handlers also always has slots available, we can do this.
Otherwise we can probably run into the same issues here as we could with destruction.
Used in conjunction with try_array_init, can't deref beforehand.
I'm explicitly passing the object to process_nested_data now. When I tried to use Z_OBJ_P(rval) things started failing in odd ways and I have no idea why. The variable doesn't seem to be overwritten...
It's rather unlikely that these will be available as CEs at this point, we need to look them up.
I don't think it can happen right now, but will once there is full preloading support for this.
RFC: https://wiki.php.net/rfc/typed_properties_v2 This is a squash of PR #3734, which is a squash of PR #3313. Co-authored-by: Bob Weinand <bobwei9@hotmail.com> Co-authored-by: Joe Watkins <krakjoe@php.net> Co-authored-by: Dmitry Stogov <dmitry@zend.com>
Merged via e219ec1. |
@nikic, is there any chance for typed callable properties in PHP 8? Personally, this is the only thing holding me back from fully loving PHP. Even though the context problems outlined in the consistent callables RFC are fair and square, language consistency is also important and much appreciated. Typed parameters and return types basically ignore the fact whether the callable is actually callable from this scope/context. This isn't the case with properties. Here are my reasons for supporting typed callable properties:
Best regards, |
@moliata I doubt we will ever support |
RFC: https://wiki.php.net/rfc/typed_properties_v2
This is a squashed version of #3313 to make final review easier. The previous thread has become unwieldy.