Skip to content
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

Support intersection types (PHP 8.1+ / Promise v2) #195

Merged
merged 2 commits into from Feb 4, 2022

Conversation

bzikarsky
Copy link
Contributor

PHP8's reflection API changed to make room for handling of union-types. As one of the consequences ReflectionParameter::getClass got marked as deprecated.
This commit moves the legacy path behind a version-check for PHP versions before 8 and adds a new more complex path for PHP8+.

Fixes #192.

@bzikarsky

This comment has been minimized.

@bzikarsky bzikarsky mentioned this pull request Sep 28, 2021
@bzikarsky bzikarsky changed the title Avoid a E_DEPRECATED in _checkTypehint on PHP8 Avoid an E_DEPRECATED in _checkTypehint on PHP8 Sep 29, 2021
@SimonFrings
Copy link
Member

@bzikarsky I added a new PR (#197). What do you think about this?

@clue
Copy link
Member

clue commented Oct 7, 2021

@bzikarsky Thank you for filing this PR, some very good changes in here!

I think the original PR filed in #176 by @cdosoftei and rebased in #197 by @SimonFrings is an excellent starting point for PHP 8 support as it also adds additional tests to ensure this behavior is consistent across versions. Perhaps we can get this in first and then rebase your work with regards to intersection types in PHP 8.1 on top of this PR with some additional tests?

Either way, keep it up! 👍

@bzikarsky
Copy link
Contributor Author

I'll rebase and add matching tests once the other MR is merged. 👍

@SimonFrings
Copy link
Member

@bzikarsky My PR is merged. 👍
Do you plan to pick this up again or do you want me to take a look at this? :shipit:

@bzikarsky
Copy link
Contributor Author

Thanks for reminding me. I'll add it to this week's TODOs and hope that I don't get overwhelmed :-)

@bzikarsky
Copy link
Contributor Author

Rebased and slightly adjusted.

@SimonFrings
Copy link
Member

@bzikarsky Thanks for the update. 🔥
Can you add additional tests to ensure your changes work as expected?

@bzikarsky
Copy link
Contributor Author

Good point. Yes, of course.

There will only be an 8.1-only test for the intersection types though. For everything else it is just a refactoring.

@bzikarsky
Copy link
Contributor Author

Pushed additional testcases in a separate commit for reviewability - Should be squashed before merge.

Copy link
Member

@SimonFrings SimonFrings left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tests, just added two minor request ^^

tests/fixtures/CountableException.php Outdated Show resolved Hide resolved
tests/fixtures/CountableNonException.php Outdated Show resolved Hide resolved
@SimonFrings
Copy link
Member

@clue @WyriHaximus What are your thoughts on this?

Copy link
Member

@WyriHaximus WyriHaximus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside from the nits @SimonFrings mentioned this looks good to me 👍

@WyriHaximus WyriHaximus requested review from clue and jsor December 4, 2021 17:10
@WyriHaximus WyriHaximus added this to the v2.9.0 milestone Dec 4, 2021
@peter17
Copy link

peter17 commented Dec 22, 2021

Hi! Can this be merged and 2.9.0 tagged? Thanks! Regards!

@peter17
Copy link

peter17 commented Feb 2, 2022

@clue @jsor sorry to bother but can you please review? thanks a lot!

@clue clue changed the title Avoid an E_DEPRECATED in _checkTypehint on PHP8 Support intersection types (PHP 8.1+ / Promise v2) Feb 4, 2022
Copy link
Member

@clue clue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bzikarsky Thank you very much for much for keeping up with this and filing this high-quality PR! 👍 Functionally, the changes LGTM and I'd like to get this in as-is :shipit:

As discussed in this ticket and linked tickets, this PR has evolved quite a bit since it was originally filed and parts of the original functionality have already been merged via other PRs. Here's the rundown:

Sorry for the confusion above! I've just updated the PR title to reflect what this PR (now) does. If you can squash your changes (and update the commit message) to reflect this, I'm happy to get this in as-is :shipit:

(For the reference: Once this is in, we still need to port this to Promise v3. We don't have a strong policy in place about this, but for all other PRs we've gone the opposite route of first merging for Promise v3 and then backporting to v2, but either approach works for me.)

Thanks for your excellent work, keep it up! 👍

@bzikarsky
Copy link
Contributor Author

Do you want to keep the refactoring of _checkTypehint and the feature+tests in two commits? Or do you prefer one?

Once we have this in, I'm happy to create a second PR with the changes applied to Promise v3.

@clue
Copy link
Member

clue commented Feb 4, 2022

Do you want to keep the refactoring of _checkTypehint and the feature+tests in two commits? Or do you prefer one?

I would argue that each functional changes should come with additional tests as part of the same commit. Leaving the refactoring in a separate commit sounds reasonable, but I'll leave this up to you to decide 👍

Once we have this in, I'm happy to create a second PR with the changes applied to Promise v3.

Awesome! 👍

bzikarsky and others added 2 commits February 4, 2022 14:00
PHP8's reflection API changed to make room for handling of union-types. As one of the consequences `ReflectionParameter::getClass` got marked as deprecated.
While the bug got already fixed in the meantime, the proposed code clears up the code-path for future features like PHP8.1's intersection-types.
@bzikarsky
Copy link
Contributor Author

I prefer the separation of refactoring and feature as well. Tests are squashed into the feature. had to rebase once more though.

From my perspective: Good to go! 👍

Copy link
Member

@clue clue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bzikarsky Thank you for this high-quality PR, changes LGTM! 👍

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

Successfully merging this pull request may close these issues.

None yet

9 participants