peachpiecompiler / peachpie

PeachPie - the PHP compiler and runtime for .NET and .NET Core
https://www.peachpie.io
Apache License 2.0
2.38k stars 203 forks source link

Closures inside classes cannot acces their private methods dynamically #114

Closed roberthusak closed 7 years ago

roberthusak commented 7 years ago

The reason for this is the missing type context of such call site (related to #96). See the following test case:

<?php
class A {
  private function foo() {
    echo "foo";
  }

  public function bar($method) {
    $fn = function() use ($method) {
      $this->$method();
    };
    $fn();
  }
}

(new A)->bar('foo');

Expected result: foo Actual result: 'foo' not found

jakubmisek commented 7 years ago

implemented in https://github.com/peachpiecompiler/peachpie/commit/af3030400f90edc4c0d1bf212d042ab0ee87849a