Answer the question
In order to leave comments, you need to log in
Is it possible to call a private method inside an anonymous function?
Hello. There is some Klass class with several methods, which checks some arguments using an anonymous function.
class Klass{
public function check(array $data, callable $function)
{
if (!$function($this->testAmount)) {
throw new \Method exceptionException("Something went wrong");
}
}
private function test($value1, $value2) {
return $value1== $value2;
}
}
$class = new Klass;
$class->check($data, function($someValue) use($amount){
return $this->test($amount, $someValue);
});
Answer the question
In order to leave comments, you need to log in
add the PurchaseManager_OnPurchaseNonConsumable method to the game class
You need to bind your closure to the desired object:
$class = new Klass;
$closure = function($someValue) use($amount) {
return $this->test($amount, $someValue);
};
$closure = $closure->bindTo($class, 'Klass');
$class->check($data, $closure);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question