Answer the question
In order to leave comments, you need to log in
Type hint. Returns not what is expected. Where is the mistake?
In the example: echo foo($object, "func"); should return - MyClass::func, but returns MyClass::__invoke.
Thank you.
class MyClass{
function func(){
return __METHOD__;
}
static function staticMethod(){
return __METHOD__;
}
function __invoke(){
return __METHOD__;
}
}
$object = new MyClass();
function foo(callable $x){
return $x();
}
echo foo($object, "func"); // MyClass::func (возвращает MyClass::__invoke)
echo foo(["MyClass", "staticMethod"]); // MyClass::staticMethod
echo foo($object); // MyClass::__invoke
Answer the question
In order to leave comments, you need to log in
Having limits the already prepared data selection. Yours doesn't have a table_schema column.
Change to where.
$object contains __invoke , which means it is callable . The foo function just calls it.
We get:
Same as:$object(); // Вызов метода __invoke
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question