Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Config] Fix signature generation with nested attributes on PHP 8.1#43267

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@agustingomes
Copy link
Contributor

@agustingomesagustingomes commentedSep 30, 2021
edited by nicolas-grekas
Loading

QA
Branch?4.4
Bug fix?yes
New feature?no
Deprecations?no
TicketsFix#43260, part of#41552
LicenseMIT
Doc PR-

This fix allows the new PHP 8.1 syntax ofnew in initializers

It allows the method signature to be inferred from the object that is the default parameter value.

derrabus reacted with rocket emoji
@nicolas-grekas
Copy link
Member

nicolas-grekas commentedOct 1, 2021
edited
Loading

Thanks for the PR! I spend some time on the topic this morning and shared our findings with Nikita.
He's proposingphp/php-src#7540 and that'd be perfect for our use case!
This also needs to be taken into account for attributes. Note that since 8.1,ReflectionAttribute has a__toString method that we can use to compute their hash. Can you please update the PR accordingly?

agustingomes reacted with thumbs up emoji

@agustingomes
Copy link
ContributorAuthor

I will add a scenario for the attributes as well. I'll keep an eye on that PR from Nikita.

nicolas-grekas reacted with thumbs up emoji

@agustingomes
Copy link
ContributorAuthor

agustingomes commentedOct 1, 2021
edited
Loading

@nicolas-grekas given the proposal of Nikita was merged, I'll wait for the next RC to come out and I'll validate if any implementation changes are still needed. If not, I'll still add the test cases for completeness. Thank you for looking into it!

@nicolas-grekasnicolas-grekas changed the titleAllow signature generation when methods use new in initializers[Config] Fix signature generation when methods use new in initializersOct 2, 2021
@nicolas-grekasnicolas-grekas changed the title[Config] Fix signature generation when methods use new in initializers[Config] Fix signature generation with nested attributes on PHP 8.1Oct 2, 2021
@nicolas-grekas
Copy link
Member

We should make this pass:

--- a/src/Symfony/Component/Config/Tests/Resource/ReflectionClassResourceTest.php+++ b/src/Symfony/Component/Config/Tests/Resource/ReflectionClassResourceTest.php@@ -126,6 +126,10 @@ EOPHP;             yield [true, 0, '#[Foo]'];         }+        if (\PHP_VERSION_ID >= 80100) {+            yield [true, 0, '#[Foo(new MissingClass)]'];+        }+         yield [true, 1, 'abstract class %s'];         yield [true, 1, 'final class %s'];         yield [true, 1, 'class %s extends Exception'];@@ -162,6 +166,10 @@ EOPHP;             yield [false, 9, 'private string $priv;'];         }+        if (\PHP_VERSION_ID >= 80100) {+            yield [true, 17, 'public function ccc($bar = new MissingClass()) {}'];+        }+         yield [true, 17, 'public function ccc($bar = 187) {}'];         yield [true, 17, 'public function ccc($bar = ANOTHER_ONE_THAT_WILL_NEVER_BE_DEFINED_CCCCCCCCC) {}'];
agustingomes reacted with thumbs up emoji

@agustingomesagustingomesforce-pushed thenew-in-initializer-fix branch 2 times, most recently from946c557 tod2ca566CompareOctober 15, 2021 07:41
@agustingomes
Copy link
ContributorAuthor

@nicolas-grekas I validated that thephp/php-src#7540 fixes the initially reported behavior, and I added changes to account for the scenarios you mentioned.

However, the 7.4 tests are failing because something in the Core component. seems unrelated to my changes at first. Can you advice how to proceed?

$defaults[$p->name] =$p->getDefaultValue();
try {
$defaults[$p->name] =$p->getDefaultValue();
}catch (\Throwable$e) {

Choose a reason for hiding this comment

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

here also a cast to string is the way to go on PHP 8.1

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

unfortunately here this won't work.

In the test case where we expect line 13 to change:

  • fromprotected function prot($a = []) {}
  • toprotected function prot($a = [123]) {}

it fails because the string casting loses the value of the array item, being it's output like this:Parameter #0 [ <optional> $a = Array ].

The string casting in the other places does work as expected.

Choose a reason for hiding this comment

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

this is unexpected to me /cc@nikic wdyt?

Choose a reason for hiding this comment

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

Let's wait for RC5 :)
Seephp/php-src@fb5cff1

agustingomes reacted with thumbs up emoji
@nicolas-grekas
Copy link
Member

Thank you@agustingomes.

agustingomes reacted with thumbs up emoji

@nicolas-grekasnicolas-grekas merged commit078df14 intosymfony:4.4Oct 29, 2021
@nicolas-grekas
Copy link
Member

And thank you@nikic!

agustingomes reacted with thumbs up emoji

@agustingomesagustingomes deleted the new-in-initializer-fix branchOctober 30, 2021 17:38
This was referencedNov 22, 2021
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

@derrabusderrabusderrabus left review comments

Assignees

No one assigned

Projects

None yet

Milestone

4.4

Development

Successfully merging this pull request may close these issues.

4 participants

@agustingomes@nicolas-grekas@derrabus@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp