Bug #66811 [Com]: Cannot access static::class in lambda, writen outside of a class
| From: | vovan-ve at yandex dot ru | Date: | Tue, 13 May 2014 11:32:06 +0000 |
| Subject: | Bug #66811 [Com]: Cannot access static::class in lambda, writen outside of a class | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-185792@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=66811&edit=1
ID: 66811
Comment by: vovan-ve at yandex dot ru
Reported by: vovan-ve at yandex dot ru
Summary: Cannot access static::class in lambda, writen
outside of a class
Status: Open
Type: Bug
Package: Scripting Engine problem
PHP Version: 5.5.9
Block user comment: N
Private report: N
New Comment:
PHP 5.3 allow us to use $object::CONSTANT, but $object::class doesn't work in the same manner,
which would be better than get_class($object).
Previous Comments:
------------------------------------------------------------------------
[2014-03-03 05:08:08] vovan-ve at yandex dot ru
Description:
------------
Since PHP 5.4 a closure can be bound to a object of a class to work like a method.
Since PHP 5.5 class name can be fetched with special syntax SomeClass::class, like a pseudo-constant
with name 'class'.
This second feature does not work in a lambda, writen outside of a class. It cause syntax error.
Test script in a sandbox: http://3v4l.org/XO0bZ
May be, related with #66622 ?
Test script:
---------------
<?php
class A {
const BAZ = 37;
public static function f() {
return static function () {
var_dump(static::BAZ);
var_dump(static::class);
};
}
}
$f = A::f();
$f();
$g = $f->bindTo(null, A::class);
$g();
$foo = static function () {
var_dump(static::BAZ);
var_dump(static::class); // line 21 is here
};
$bar = $foo->bindTo(null, A::class);
$bar();
Expected result:
----------------
int(37)
string(1) "A"
int(37)
string(1) "A"
int(37)
string(1) "A"
Actual result:
--------------
Fatal error: Cannot access static::class when no class scope is active in ... on line 21
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=66811&edit=1