You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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();
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
, andstatic
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+:
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?
The text was updated successfully, but these errors were encountered: