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

Incorrectly identified usage of $this in static method #273

Open
kornrunner opened this issue Dec 20, 2018 · 0 comments
Open

Incorrectly identified usage of $this in static method #273

kornrunner opened this issue Dec 20, 2018 · 0 comments

Comments

@kornrunner
Copy link

Example:

<?php

class Foo {
    private $bar = 'baz';
}

class Test  {
    public static function run () {
        $getter  = function () { return $this->bar; };
        $closure = Closure::bind($getter, new Foo(), Foo::class);
        return $closure();
    }
}

echo Test::run() . "\r\n";

Reports error $this can not be used in static methods.:

{
    "resource": "/closure.php",
    "owner": "_generated_diagnostic_collection_name_#2",
    "severity": 8,
    "message": "$this can not be used in static methods.",
    "source": "php",
    "startLineNumber": 9,
    "startColumn": 41,
    "endLineNumber": 9,
    "endColumn": 46
}

Code itself is valid:

$ php -l closure.php 
No syntax errors detected in closure.php
$ php closure.php 
baz
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

No branches or pull requests

1 participant