Bug #68194 [Com]: Closure captures late bound class too eagerly
| From: | levim@php.net | Date: | Fri, 17 Oct 2014 13:58:38 +0000 |
| Subject: | Bug #68194 [Com]: Closure captures late bound class too eagerly | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-188165@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=68194&edit=1
ID: 68194
Comment by: levim@php.net
Reported by: denis at slik dot eu
Summary: Closure captures late bound class too eagerly
Status: Assigned
Type: Bug
Package: Scripting Engine problem
Operating System: Irrelevant
PHP Version: 5.6.1
Assigned To: levim
Block user comment: N
Private report: N
New Comment:
To be completely honest, I am not sure why Right and Base can access a protected property in Left.
The behavior of the closure actually seems correct to me.
I'll have to poke around in documentation and talk to more people. Thank you for this report.
Previous Comments:
------------------------------------------------------------------------
[2014-10-17 13:18:43] tyrael@php.net
Levi, could you look into this please?
------------------------------------------------------------------------
[2014-10-09 06:54:43] denis at slik dot eu
Description:
------------
In #66622, Closures have been changed to capture the late bound class very eagerly to make the
static keyword work.
This had a side effect of backwards-incompatible visibility breaking.
For a full example, see http://3v4l.org/O5dLF.
This worked in <=5.4.29, <=5.5.13, but breaks in >=5.4.30, >=5.5.14, >=5.6.1.
It would seem sensible that refactoring the code inside a closure would not change the visibility
restrictions.
Test script:
---------------
class Base {
public static function hi() {
echo Left::$prot;
$cl = function(){
echo Left::$prot;
};
$cl();
}
}
class Left extends Base {
protected static $prot = "works\n";
}
class Right extends Base {
}
Right::hi();
Expected result:
----------------
works
works
Actual result:
--------------
works
Fatal error: Cannot access protected property Left::$prot
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=68194&edit=1