Bug #66811 [NEW]: Cannot access static::class in lambda, writen outside of a class

From: Date: Mon, 03 Mar 2014 05:08:09 +0000
Subject: Bug #66811 [NEW]: Cannot access static::class in lambda, writen outside of a class
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-184499@lists.php.net to get a copy of this message
From: vovan-ve at yandex dot ru Operating system: PHP version: 5.5.9 Package: Scripting Engine problem Bug Type: Bug Bug description:Cannot access static::class in lambda, writen outside of a class 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 bug report at https://bugs.php.net/bug.php?id=66811&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=66811&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=66811&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=66811&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=66811&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=66811&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=66811&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=66811&r=needscript Try newer version: https://bugs.php.net/fix.php?id=66811&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=66811&r=support Expected behavior: https://bugs.php.net/fix.php?id=66811&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=66811&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=66811&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=66811&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66811&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=66811&r=dst IIS Stability: https://bugs.php.net/fix.php?id=66811&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=66811&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=66811&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=66811&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=66811&r=mysqlcfg

« previous php.bugs (#184499) next »