|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66811 Cannot access static::class in lambda, writen outside of a class
Submitted: 2014-03-03 05:08 UTC Modified: 2015-05-06 16:17 UTC
Avg. Score:2.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: vovan-ve at yandex dot ru Assigned: nikic (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.5.9 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: vovan-ve at yandex dot ru
New email:
PHP Version: OS:


 [2014-03-03 05:08 UTC] vovan-ve at yandex dot ru
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:

May be, related with #66622 ?

Test script:
class A {
    const BAZ = 37;

    public static function f() {
        return static function () {

$f = A::f();

$g = $f->bindTo(null, A::class);

$foo = static function () {
    var_dump(static::class);    // line 21 is here

$bar = $foo->bindTo(null, A::class);

Expected result:
string(1) "A"
string(1) "A"
string(1) "A"

Actual result:
Fatal error: Cannot access static::class when no class scope is active in ... on line 21


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-05-13 11:32 UTC] vovan-ve at yandex dot ru
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).
 [2015-05-06 15:33 UTC]
-Assigned To: +Assigned To: nikic
 [2015-05-06 16:17 UTC]
-Status: Assigned +Status: Closed
 [2015-05-06 16:17 UTC]
Fixed in PHP 7 by This won't be backported, as it depends on a bunch of other changes, some ABI incompatible.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Fri Dec 01 09:01:27 2023 UTC