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

Do not flag self and static keywords in closures defined inside a class #68

Closed
david-binda opened this issue Feb 8, 2019 · 1 comment

Comments

@david-binda
Copy link

The static, self and $this inside closures defined inside class scope in PHP prior to 5.4.0 produced fatal errors. But PHP 5.4.0 automatically bounds current class' scope to closure, making $this, self, and static available inside of the function's scope.

The logic for flagging self inside closures was introduced 8 years ago ( 20 Jul 2011
), prior the release of PHP 5.4.0 (which happened on 01 Mar 2012 ).

Following code is valid in PHP 5.4+:

<?php

class My_Class {

    protected static $output = 'test';

    public static function method() {
        return function() {
            echo self::$output;
        };
    }
}

$object = new My_Class;
$function = $object->method();
$function();

See https://3v4l.org/B43Uj and https://3v4l.org/sdJ6Q with code examples and their processing in different PHP versions (works as expected in PHP 5.4+).

Perhaps it's time to stop flagging those usages?

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

2 participants