<!DOCTYPE html>
<html>
<body>
<?php
function printFormatted(callable $format, $str) {
echo $format($str);
echo "<br>";
}
class MyClass {
public static function ask($str) {
return $str . "?";
}
public function brackets($str) {
return "[$str]";
}
}
$func = function($str) { return substr($str, 0, 5); };
printFormatted($func , "Hello World");
printFormatted("strtoupper", "Hello World");
printFormatted(["MyClass", "ask"], "Hello World");
$obj = new MyClass();
printFormatted([$obj, "brackets"], "Hello World");
?>
</body>
</html>