I have encountered a strange problem. I am working on a program which should work on PHP5.3 . Today, a server with PHP5.3.5 installed gave me the following error when running my program:Fatal error: Cannot access self:: when no class scope is active on line 19
I do not have this problem on any other server with later PHP versions. But I have to find a solution nevertheless.
To make the problem easy to understand, I made the following little script. Basically I call a global function with a closure as parameter which calls a private static function.
I researched this problem and it seems Closure::bind
would be the solution, but is only available for PHP5.4+. I need a solution for PHP5.3 and I am at a dead end.
<?php
function doSth($c)
{
$c();
}
class foo
{
private static function bar()
{
echo 'OK';
}
public static function go()
{
doSth(function()
{
self::bar();
});
}
}
foo::go();