Source Code:
(back to article)
<?php // Example 1 function myFunction(callable $callback) { $result = $callback(); return $result; } function myCallback() { return "Hello world!"; } echo myFunction("myCallback") . PHP_EOL; // Output: Hello world! // Example 2 class MyClass { public function myMethod() { return "Hello world!"; } } $myObject = new MyClass(); echo myFunction([$myObject, "myMethod"]); // Output: Hello world!
Result:
Report an issue