Bug #66622 [Asn->Csd]: Closures do not correctly capture the late bound class (static::) in some cases
Edit report at https://bugs.php.net/bug.php?id=66622&edit=1
ID: 66622
Updated by: stas@php.net
Reported by: drewparoski at gmail dot com
Summary: Closures do not correctly capture the late bound
class (static::) in some cases
-Status: Assigned
+Status: Closed
Type: Bug
Package: Scripting Engine problem
Operating System: CentOS Linux 6.3
PHP Version: 5.5.8
Assigned To: levim
Block user comment: N
Private report: N
New Comment:
The fix for this bug has been committed.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
For Windows:
http://windows.php.net/snapshots/
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2014-05-11 03:05:07] levim@php.net
Github is down at the moment; pull request will come in on Monday.
------------------------------------------------------------------------
[2014-05-08 18:06:46] levim@php.net
Related To: Bug #67222
------------------------------------------------------------------------
[2014-02-04 01:39:45] drewparoski at gmail dot com
Verified this happens on PHP 5.5.8, which is the current official release. Updated the version
number for this bug accordingly, though it's worth noting this bug still happens on PHP
5.6.0alpha1 as well.
------------------------------------------------------------------------
[2014-02-01 02:29:31] drewparoski at gmail dot com
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 this bug report at https://bugs.php.net/bug.php?id=66622&edit=1
Thread (7 messages)