Skip to content

Add support for generating class entries from stubs #6289

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

Closed
wants to merge 9 commits into from

Conversation

kocsismate
Copy link
Member

No description provided.

@kocsismate kocsismate marked this pull request as draft October 7, 2020 10:41
@nikic nikic added this to the PHP 8.1 milestone Oct 7, 2020
@ondrejmirtes
Copy link
Contributor

Beautiful! I noticed that some properties have a PHPDoc type and some have a native type. Is there still time to take the major version opportunity to turn more of them to native type (not just in stubs but in the actual implementation)? It’d be beneficial because overriden properties in child classes need to have the same native type (they’re invariant).

@kocsismate
Copy link
Member Author

Is there still time to take the major version opportunity to turn more of them to native type

@ondrejmirtes No, unfortunately, it's way too late to do so, despite how tempting it is.

@ondrejmirtes
Copy link
Contributor

Looking at the milestone - this isn't gonna make PHP 8.0?

@kocsismate
Copy link
Member Author

kocsismate commented Oct 8, 2020

Looking at the milestone - this isn't gonna make PHP 8.0?

At first, I was also a tiny little bit surprised, but after rethinking, it's a substantial change (especially the code generation part), and we've already after the very last days.

The only reason why it could make sense to still allow this into PHP 8.0 is to avoid merge conflicts due to changes in stub hashes. I'm not sure how often we'll have to fix php 8.0. signatures, but I'd expect a non-negligible amount, since they are very new. personally, I'd also be ok with a compromise, and just add the properties for php 8.0 without code generation, but it's Nikita's and the release managers' call.

@ondrejmirtes
Copy link
Contributor

OK, thanks for the heads up. I just realized I can use the stubs in PHPStan in a little bit different way and essentially just read the parameter names and types and the return types (instead of using them as the full reflection representation), which is how they're meant to be used anyway :)

@ondrejmirtes
Copy link
Contributor

Alright, managed to make it work :) https://twitter.com/OndrejMirtes/status/1314218370682818561

@kocsismate kocsismate force-pushed the stub-properties branch 2 times, most recently from 4da323a to 4506600 Compare October 8, 2020 21:48
@kocsismate kocsismate marked this pull request as ready for review October 8, 2020 21:49
@kocsismate kocsismate force-pushed the stub-properties branch 2 times, most recently from a8c168f to cdc8f3a Compare October 8, 2020 22:39
@kocsismate kocsismate changed the title Add support for declaring properties in stubs Add support for generating class entries in stubs Oct 8, 2020
@kocsismate kocsismate changed the title Add support for generating class entries in stubs Add support for generating class entries from stubs Oct 9, 2020
@kocsismate kocsismate force-pushed the stub-properties branch 5 times, most recently from 5a936ed to 149da82 Compare October 10, 2020 21:48
@kocsismate kocsismate force-pushed the stub-properties branch 2 times, most recently from 6f795fe to e207879 Compare October 20, 2020 20:20
@kocsismate
Copy link
Member Author

@nikic Now that PHP 8.0.0 is done (although methodsynopsis generation is yet to be finished), can you please take a look at this PR again sometime soon? AFAIR the main concern currently is how it works for classes overriding the get_iterator handler. In my last commit, I generated a few such class entries, but I'm not sure if there is any related issue.

kocsismate and others added 3 commits January 19, 2021 11:47
RepresentableType has been replaced by ArginfoType. This is only
a partial fix, in that we still need to handle class union types.
@nikic
Copy link
Member

nikic commented Jan 19, 2021

@nikic Now that PHP 8.0.0 is done (although methodsynopsis generation is yet to be finished), can you please take a look at this PR again sometime soon? AFAIR the main concern currently is how it works for classes overriding the get_iterator handler. In my last commit, I generated a few such class entries, but I'm not sure if there is any related issue.

I think ultimately, setting get_iterator after doing the implements is okay as well. I think the only negative effect this has is that an unnecessary zend_class_iterator_funcs structure can be created. But apart from that, I think everything will work correctly.

@nikic
Copy link
Member

nikic commented Jan 19, 2021

Okay, my first fix for the exception issue wasn't quite right. It caused phpdbg failures on windows. Hopefully this one works.

@nikic
Copy link
Member

nikic commented Jan 19, 2021

This generally looks good to me, nice work!

@kocsismate
Copy link
Member Author

Thanks for the review and the fixes! I can take care of the rest later this week :)

@kocsismate kocsismate force-pushed the stub-properties branch 3 times, most recently from 410e274 to 0e46245 Compare January 25, 2021 22:54
@php-pulls php-pulls closed this in 1954e59 Jan 26, 2021
@kocsismate kocsismate deleted the stub-properties branch January 26, 2021 10:56
@kocsismate
Copy link
Member Author

@nikic Thanks again for the help! I'll start migrating the stubs to use @generate-class-entries in the following days. And I think I can also add support for registering properties which have a union type containing multiple classes a bit later. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants