Bug #66622 [NEW]: Closures do not correctly capture the late bound class (static::) in some cases

From: Date: Sat, 01 Feb 2014 02:29:31 +0000
Subject: Bug #66622 [NEW]: Closures do not correctly capture the late bound class (static::) in some cases
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-184110@lists.php.net to get a copy of this message
From: drewparoski at gmail dot com Operating system: CentOS Linux 6.3 PHP version: 5.6.0alpha1 Package: Scripting Engine problem Bug Type: Bug Bug description:Closures do not correctly capture the late bound class (static::) in some cases Description: ------------ When a PHP closure is created, it is supposed to capture the late bound class of the enclosing function. There are a number of cases involving derived classes and static methods or static closures (or both) where it doesn't work correctly. The test script I've included demonstrates the problem. I've tested it on PHP 5.6.0alpha1, but I can also reproduce the problem on various builds of PHP 5.5. Test script: --------------- <?php class A { static function name() { return 'A'; } function foo() { $fn = function() { return static::name(); }; echo static::name() . ' vs ' . $fn() . "\n"; } function bar() { $fn = static function() { return static::name(); }; echo static::name() . ' vs ' . $fn() . "\n"; } static function baz() { $fn = function() { return static::name(); }; echo static::name() . ' vs ' . $fn() . "\n"; } } class B extends A { static function name() { return 'B'; } } function test() { (new B)->foo(); B::foo(); (new B)->baz(); B::baz(); (new B)->bar(); B::bar(); } test(); Expected result: ---------------- B vs B B vs B B vs B B vs B B vs B B vs B Actual result: -------------- B vs B B vs A B vs A B vs A B vs A B vs A -- Edit bug report at https://bugs.php.net/bug.php?id=66622&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=66622&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=66622&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=66622&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=66622&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=66622&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=66622&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=66622&r=needscript Try newer version: https://bugs.php.net/fix.php?id=66622&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=66622&r=support Expected behavior: https://bugs.php.net/fix.php?id=66622&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=66622&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=66622&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=66622&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66622&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=66622&r=dst IIS Stability: https://bugs.php.net/fix.php?id=66622&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=66622&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=66622&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=66622&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=66622&r=mysqlcfg

« previous php.bugs (#184110) next »