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

[ErrorHandler] resolve class constant types when patching return types#58536

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
xabbuh merged 1 commit intosymfony:7.2fromxabbuh:pr-58493
Oct 14, 2024

Conversation

@xabbuh
Copy link
Member

QA
Branch?7.2
Bug fix?yes
New feature?no
Deprecations?no
Issues
LicenseMIT

account for types like the ones added in#58493

@carsonbotcarsonbot added this to the7.2 milestoneOct 10, 2024
@carsonbotcarsonbot changed the title[ErrorHandler] resolve class constant types when patching return types[ErrorHandler] resolve class constant types when patching return typesOct 10, 2024
@stof
Copy link
Member

Can you add a test covering this (probably in the existing testsDebugClassLoaderTest::testReturnType) ?

default =>$definingClass,
};

if (!\defined($definingClass.'::'.$definingClass)) {
Copy link
Member

Choose a reason for hiding this comment

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

what will happen here for things likeCookie::SAMESITE_* ?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

We ignore them for now. The changes from this PR require that you use the full constant name. We could ship support for wildcards in a follow-up PR (I would like to ship this one as soon as possible to make the job green again and supporting wildcards requires a bit more work).

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with ignoring them (we were already ignoring those cases before, see the comment below). But I'm wondering whether this will be ignored cleaning here.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Yes, returning here (which means not reaching the line where the$returnTypes property is written for the current method means that no patching happens afterwards. The same is done for example further down for theresource type.


$constant =new \ReflectionClassConstant($definingClass,$constantName);

if (method_exists(\ReflectionClassConstant::class,'getType') &&$constantType =$constant->getType()) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we replace themethod_exists check with aPHP_VERSION_ID check ? This has 2 benefits:

  • it will make it clearer when we can simplify that check thanks to our min requirement
  • it will be resolved at compile-time

xabbuh reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

done

$constant =new \ReflectionClassConstant($definingClass,$constantName);

if (method_exists(\ReflectionClassConstant::class,'getType') &&$constantType =$constant->getType()) {
$n =$constantType->getName();
Copy link
Member

Choose a reason for hiding this comment

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

is the constant type guaranteed to be a ReflectionNamedType in PHP ?https://github.com/php/php-src/blob/9345582471d5dfa8b783b1e666d8b76620f542f9/ext/reflection/php_reflection.stub.php#L626C32-L626C47 seems to answer "no"

Copy link
MemberAuthor

@xabbuhxabbuhOct 11, 2024
edited
Loading

Choose a reason for hiding this comment

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

I guess the stub is not correct here. I added a test covering this line and$constantType is indeed an instance ofReflectionNamedType.

I stand corrected here. A constant can indeed have union or intersection types (see the examples in the RFC:https://wiki.php.net/rfc/typed_class_constants).

Copy link
Member

Choose a reason for hiding this comment

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

well, if the type you use is a named type, it will. But do constant types allows using union or intersection types ? Those are not named types.

Copy link
MemberAuthor

@xabbuhxabbuhOct 11, 2024
edited
Loading

Choose a reason for hiding this comment

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

Yes, they can be union or intersection types (see my edit above). I've opted to ignore them for now in this PR. We can consider to add support for them in the future (similar to the support for wildcards). But I do not see an urgent need for that right now (for wildcards that's a bit different as we make use of them in Symfony).

@xabbuhxabbuhforce-pushed thepr-58493 branch 2 times, most recently from3c91c04 to60553b9CompareOctober 11, 2024 21:21
@xabbuh
Copy link
MemberAuthor

@stof test added

@xabbuhxabbuh merged commitc3f10c3 intosymfony:7.2Oct 14, 2024
8 of 10 checks passed
@xabbuhxabbuh deleted the pr-58493 branchOctober 14, 2024 09:01
@Zausenec
Copy link

With01eb32cdanog\MadelineProto not working

Attempted to load class "AbstractAPI" from namespace "danog\MadelineProto".Did you forget a "use" statement for "danog\MadelineProto\Namespace\AbstractAPI"?

Both classes danog\MadelineProto\AbstractAPI and danog\MadelineProto\Namespace\AbstractAPI are exists
Without this commit all works as expected

@xabbuh
Copy link
MemberAuthor

@Zausenec please open a new issue and provide a small example application that allows to reproduce it.

@Zausenec
Copy link

Zausenec commentedNov 30, 2024
edited
Loading

@Zausenec please open a new issue and provide a small example application that allows to reproduce it.

#59051

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@stofstofstof approved these changes

@alexandre-dauboisalexandre-dauboisalexandre-daubois approved these changes

@mtarldmtarldmtarld approved these changes

@chalasrchalasrchalasr approved these changes

@ycerutoycerutoAwaiting requested review from ycerutoyceruto is a code owner

Assignees

No one assigned

Projects

None yet

Milestone

7.2

Development

Successfully merging this pull request may close these issues.

7 participants

@xabbuh@stof@Zausenec@alexandre-daubois@mtarld@chalasr@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp