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

[Console] Do not call non-static method via class-name#62822

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

Open
keradus wants to merge7 commits intosymfony:7.3
base:7.3
Choose a base branch
Loading
fromkeradus:7.3_fix_callback

Conversation

@keradus
Copy link
Member

@keraduskeradus commentedDec 19, 2025
edited
Loading

QA
Branch?7.3
Bug fix?yes-ish
New feature?no
Deprecations?no
IssuesFix compiler complaints
LicenseMIT

extracted from PR#62821 against 8.1, but targeting 7.3 (as the earliest supported branch with the issue)

Non-static lambda is working right now by "accident", but we still call non-static methodgetSuggestedRoles using class name and not instance -suggestedValues: [self::class, 'getSuggestedRoles']). Yet, imaginegetSuggestedRoles method would start using$this...

If lambda would be declared as static, calling non-static method from it would fail regardless of not using$this inside. This is similar issue as we faced in#62794

Let's not call non-static method statically -> solution to convert method into static one.
I'm changing lambdas to static in that case as well. [it's OK they are later re-bind, as those particular lambdas not using$this context anyway]

@carsonbot
Copy link

Hey!

Thanks for your PR. You are targeting branch "8.1" but it seems your PR description refers to branch "7.3".
Could you update the PR description or change target branch? This helps core maintainers a lot.

Cheers!

Carsonbot

@carsonbotcarsonbot changed the titlefix: Console/.../InvokableCommandTest - PHP doesn't like to call non-… fix: Console/.../InvokableCommandTest - PHP doesn't like to call non-…Dec 19, 2025
@keraduskeradus changed the base branch from8.1 to7.3December 19, 2025 10:25
@keraduskeradus changed the title fix: Console/.../InvokableCommandTest - PHP doesn't like to call non-… fix: Console - do not call non-static method by class-nameDec 19, 2025
@keraduskeradus changed the title fix: Console - do not call non-static method by class-name fix: Console - do not call non-static method bviay class-nameDec 19, 2025
@keraduskeradus changed the title fix: Console - do not call non-static method bviay class-name fix: Console - do not call non-static method via class-nameDec 19, 2025
@keraduskeradus changed the title fix: Console - do not call non-static method via class-name fix: Console - do not call non-static method via class-nameDec 19, 2025
@carsonbotcarsonbot changed the title fix: Console - do not call non-static method via class-name[Console] fix: Console - do not call non-static method via class-nameDec 19, 2025
@OskarStarkOskarStark changed the title[Console] fix: Console - do not call non-static method via class-name[Console] Do not call non-static method via class-nameDec 19, 2025
@keradus
Copy link
MemberAuthor

🙇🏻

@yceruto
Copy link
Member

yceruto commentedDec 19, 2025
edited
Loading

Non-static lambda is working right now by "accident", but we still call non-static method getSuggestedRoles using class name and not instance - suggestedValues: [self::class, 'getSuggestedRoles']). Yet, imagine getSuggestedRoles method would start using $this...

For reference, we did this intentionally for this case, where it is not possible to define a callable like[$this, 'getSuggestedRoles'] or simply$this->getSuggestedRoles(...) as an attribute argument. Therefore, we first check whether the static method exists; otherwise, we switch the definition to[$this, 'getSuggestedRoles'] to allow the use of non-static values.

$self->suggestedValues = [$instance,$self->suggestedValues[1]];

The test changed here was testing that, but it was not actually invoking the method statically.

I think if we want to keep testing that feature, we should revert (the static method) and add a comment instead?

@keradus
Copy link
MemberAuthor

in such case, static analysis has no clue given lambda cannot be static [using$this later from autoreplaced value, as you explained]

if the feature is expected, it should be tested. let me revert and propose some comments

yceruto reacted with thumbs up emoji

@keradus
Copy link
MemberAuthor

i believe this explicit check against static->$this convertion was hidden. i elaborated on it in newly added comment and put an exception.

in upcoming commit, i also suggest to not declarae exception for whole file (other lambas shall be static) and handle it differently for those 2 unique lambdas.

Please re-review and decide which version you prefer (exception for whole file or workaround withassert)

#[Argument(description:'Short argument description')]string$bio ='',
// Declare callback in static context, even when method is NOT static.
// PHP doesn't allow to use `$this` here, and callback is later modified
// on-the-fly to be called on instance instead: https://github.com/symfony/symfony/blob/7.3/src/Symfony/Component/Console/Attribute/Argument.php#L87

Choose a reason for hiding this comment

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

we don't add links to github in the codebase

Suggested change
// on-the-fly to be called on instance instead: https://github.com/symfony/symfony/blob/7.3/src/Symfony/Component/Console/Attribute/Argument.php#L87
// on-the-fly to be called on instance instead

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

ack

let me apply of course,
i wonder if you have a practice how to provide such reference? it was really hidden knowledge, when looking at spec-via-tests

Copy link
Member

@nicolas-grekasnicolas-grekasDec 19, 2025
edited
Loading

Choose a reason for hiding this comment

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

you'll find references using eg@see TheClass in phpdoc

Copy link
MemberAuthor

@keraduskeradusDec 19, 2025
edited
Loading

Choose a reason for hiding this comment

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

tbh, myself, even with@see Argument::tryFrom(), i wouldn't intuitively find this behaviour, as it's not documented in that class/code and condition to apply this transformation is combined of 6 conditions 😅

Perhaps i'm too far away from this, unexpected to me, behaviour.
Perhaps, OK to add some in-code docs for this transofmation? (added last commit, feel free to revert)

keradusand others added2 commitsDecember 19, 2025 18:27
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

@chalasrchalasrAwaiting requested review from chalasrchalasr is a code owner

@xabbuhxabbuhAwaiting requested review from xabbuh

Assignees

No one assigned

Projects

None yet

Milestone

8.1

Development

Successfully merging this pull request may close these issues.

6 participants

@keradus@carsonbot@yceruto@nicolas-grekas@xabbuh@OskarStark

[8]ページ先頭

©2009-2025 Movatter.jp