Bug #68194 [Opn]: Closure captures late bound class too eagerly

From: Date: Fri, 17 Oct 2014 13:18:43 +0000
Subject: Bug #68194 [Opn]: Closure captures late bound class too eagerly
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-188161@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
 Updated by:         tyrael@php.net
 Reported by:        denis at slik dot eu
 Summary:            Closure captures late bound class too eagerly
 Status:             Open
 Type:               Bug
 Package:            Scripting Engine problem
 Operating System:   Irrelevant
 PHP Version:        5.6.1
-Assigned To:        
+Assigned To:        levim
 Block user comment: N
 Private report:     N

 New Comment:

Levi, could you look into this please?


Previous Comments:
------------------------------------------------------------------------
[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


Thread (10 messages)

« previous php.bugs (#188161) next »