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

TASK: Support PHP8 types and class property promotion #2404

Merged
merged 16 commits into from
Aug 30, 2021
Merged

Conversation

albe
Copy link
Member

@albe albe commented Mar 1, 2021

This change makes sure that PHP8 union types, nullable types and promoted properties can be used with proxied classes.

Depends on #2287
Related to #2468
Related to #2233

@albe
Copy link
Member Author

albe commented Mar 1, 2021

Apparently StyleCI does not yet support PHP 8 syntax 🤷‍♂️

This was referenced Mar 1, 2021
Neos.Flow/Classes/ObjectManagement/Proxy/ProxyClass.php Outdated Show resolved Hide resolved
Neos.Flow/Classes/ObjectManagement/Proxy/ProxyMethod.php Outdated Show resolved Hide resolved
if (count($attribute->getArguments()) > 0) {
$argumentsAsString = [];
foreach ($attribute->getArguments() as $argumentName => $argumentValue) {
$renderedArgumentValue = var_export($argumentValue, true);
Copy link
Member Author

Choose a reason for hiding this comment

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

Wondering why we didn't use var_export() in the other method where we render an array(x => y, ...) manually?

Copy link
Member

Choose a reason for hiding this comment

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

Which "other method" do you mean?

Neos.Flow/Classes/ObjectManagement/Proxy/ProxyClass.php Outdated Show resolved Hide resolved
Neos.Flow/Classes/Reflection/ReflectionService.php Outdated Show resolved Hide resolved
'@\Neos\Flow\Annotations\Validate(type="bar1", argumentName="foo1")'
],
[
new Validate(['type' => 'bar1', 'options' => ['minimum' => 2]]),
new Validate(null, 'bar1', ['minimum' => 2]),
Copy link
Member Author

@albe albe Mar 22, 2021

Choose a reason for hiding this comment

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

This shows that the choice to have argumentName as the anonymous argument was probably suboptimal. I would rather consider the validate type to be anonmyous - maybe something to consider for next major?

Question basically is: Are Validate annotations more commonly used on method arguments, or on properties? If on method arguments, is more straightforward to use @Flow\Validate("NotEmpty", argumentName="$myArg") rather than @Flow\Validate("$myArg", type="NotEmpty")?

Copy link
Member

Choose a reason for hiding this comment

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

No idea on where validation is used more. But I have no issue with @Flow\Validate("$myArg", type="NotEmpty"), TBH. What is not straighforward with that?

@albe albe changed the base branch from 7.0 to master March 23, 2021 18:46
@albe albe changed the title TASK: Add some tests for PHP8 features TASK: Support PHP8 attributes and property promotion Mar 23, 2021
@mficzel
Copy link
Member

mficzel commented Apr 16, 2021

I generally like this but consider it a bit breaky especially since the annotation api changed. Also it would be great to be able to convert the doctrine annotations at the same time.

Not sure about how fast Doctrine will be to support annotations but imho this would be great for Flow8.

@albe
Copy link
Member Author

albe commented Jun 8, 2021

As of doctrine/orm 2.9.x PHP attributes are supported, BUT their changes are breaking for us - see doctrine/orm#8753

@albe
Copy link
Member Author

albe commented Jul 2, 2021

Update: As of doctrine/orm 2.9.3+ - which is allowed now in 7.0+ as of #2496 - PHP 8 attributes work now

@albe albe changed the title TASK: Support PHP8 attributes and property promotion TASK: Support PHP8 types and class property promotion Aug 11, 2021
@albe
Copy link
Member Author

albe commented Aug 11, 2021

Note: I should propably rebase this PR to clean up the commit history in relation to #2468 and then start with a clean review cycle

@albe albe force-pushed the albe-php8 branch 2 times, most recently from b96eb37 to 78818d8 Compare August 18, 2021 13:54
@albe
Copy link
Member Author

albe commented Aug 18, 2021

Rebased cleanly now and also extracted the docblock-preserving commit into #2533

@albe
Copy link
Member Author

albe commented Aug 18, 2021

Given the psalm tests fail with the PHP8 methods - maybe it makes more sense to run psalm with latest PHP version, rather than lowest?

Regarding the lowest-deps build:

Argument 1 passed to Neos\Flow\Annotations\Scope::__construct() must be of the type string or null, array given, called in /home/runner/work/flow-development-collection/flow-development-collection/flow-development-distribution/Packages/Libraries/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php on line 825

After some digging it seems to be due to doctrine/annotations and the newly used @NamedArgumentConstructor, which only exists in doctrine/annotations 1.12+ - see doctrine/annotations#391 - that might also explain a similar error that @mficzel saw and mentioned in slack. I noticed we do not yet have a direct dependency on doctrine/annotations at all, though we definitely directly use it. So we should add that.
See #2535

Copy link
Member

@kitsunet kitsunet left a comment

Choose a reason for hiding this comment

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

Looks fine to me. Wondering a bit if any of the new features will have impact on eg AOP and if we need to do something about it. but I guess it should be fine for now.

Copy link
Contributor

@sorenmalling sorenmalling left a comment

Choose a reason for hiding this comment

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

From reading it looks fine to me.

I am a bit/very much in doubt how to properly test it deeper, to give valuable feedback

@sorenmalling
Copy link
Contributor

@albe With the new NamedConstructorAnnotation annotation you mention in #2535 - doesn't it mean that you need to have one merge before the other, and we can't do a release with only one of these merged?

@albe
Copy link
Member Author

albe commented Aug 20, 2021

@albe With the new NamedConstructorAnnotation annotation you mention in #2535 - doesn't it mean that you need to have one merge before the other, and we can't do a release with only one of these merged?

We should have both in optimally, but it only is an issue if you can't install latest doctrine/annotations in your setup for some reason. In that case you will see an error like above (in DocParser) instead of composer rejecting to install things in the worst case.

I am a bit/very much in doubt how to properly test it deeper, to give valuable feedback

Unless you have some code base using PHP8 types (union / nullable) and/or classes with property promotion, it's impossible to test deeper really :) So no worries. If you have some idea for test fixtures, i.e. exactly such classes (like https://github.com/neos/flow-development-collection/pull/2404/files#diff-d7acfbcf9e4274f911c5c5f5f23ae6f8c8cecf4d64ebcc52d40b04bc050779b3), then that would be a great addition to cover potential cases that break compilation

Edit: PS: the open TODO actually belongs to the PHP8 Attributes issue... PPS: Created #2537

@kdambekalns
Copy link
Member

7.3 / lowest fails due to Guzzle vs. Behat…

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.

5 participants