Bug #68194 [NEW]: Closure captures late bound class too eagerly
From: denis at slik dot eu
Operating system: Irrelevant
PHP version: 5.6.1
Package: Scripting Engine problem
Bug Type: Bug
Bug description:Closure captures late bound class too eagerly
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 bug report at https://bugs.php.net/bug.php?id=68194&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=68194&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=68194&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=68194&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=68194&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=68194&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=68194&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=68194&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=68194&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=68194&r=support
Expected behavior: https://bugs.php.net/fix.php?id=68194&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=68194&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=68194&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=68194&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68194&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=68194&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=68194&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=68194&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=68194&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=68194&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=68194&r=mysqlcfg
Thread (10 messages)
- denis at slik dot eu