I have a following problem: in a static method of some class A I define anonymous function within from I want to call another protected static method of the class A. The problem is I need to make it work in php 5.3. Any ideas? Here is a sample code:
class A {
public static function test()
{
$class = new static;
$f = function () use ($class) {
// problem: I need to call static::foo() from here
return $class::foo();
};
print $f();
}
protected static function foo() { return 1; }
}
class B extends A {
protected static function foo() { return 2; }
}
// assuming this will output 2
B::test();
This works in php >= 5.4, but in php 5.3 I get Fatal error: Call to protected method B::foo() from context '' ...
.
Thanks for any help.