Thanks to visit codestin.com
Credit goes to github.com

Skip to content

$this can not be used in static methods. #26279

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

Closed
OliverLeitner opened this issue Feb 23, 2018 · 2 comments
Closed

$this can not be used in static methods. #26279

OliverLeitner opened this issue Feb 23, 2018 · 2 comments
Labels

Comments

@OliverLeitner
Copy link

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? yes
Symfony version current master

file: symfony/console/Tests/Command.php

    private static function createClosure()
    {
        return function (InputInterface $input, OutputInterface $output) {
            $output->writeln(isset($this) ? 'bound' : 'not bound');
        };
    }

Causes linter error in visual studio code:

file: 'file:///.../symfony/console/Tests/Command/CommandTest.php'
severity: 'Error'
message: '$this can not be used in static methods.'
at: '401,36'
source: 'php'
code: 'undefined'

and yes... one could disable the linter...

anyways... i am sure youre already aware of this and a good solid fix is already on the way, just wanted to check in and say hi;-)

@prisis
Copy link
Contributor

prisis commented Feb 23, 2018

Hey :), you need to use self:: instead of $this-> for static methods.

For more infos http://www.brainbell.com/tutorials/php/Static_Methods.html

@xabbuh xabbuh added the Console label Feb 23, 2018
@xabbuh
Copy link
Member

xabbuh commented Feb 23, 2018

$this is not used by the static method, but it is part of the closure for which Closure::bind() makes sure that the context is set (see #20847).

@xabbuh xabbuh closed this as completed Feb 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants