Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class CurrentTime {
- public function __invoke($format) {
- return 'Invoked : ' . date($format);
- }
- public static function getCurrentDateTime($format) {
- return 'Func array : ' . date($format);
- }
- }
- $invokable = new CurrentTime();
- $function = function($format) {
- return 'Closure : ' . date($format);
- };
- $funcarray = array('CurrentTime', 'getCurrentDateTime');
- function examineCallbacks($callbacktype, $callback) {
- echo gettype($callback), ' is ', (!is_callable($callback) ? 'not ' : ''), 'callable', PHP_EOL;
- if (is_callable($callback) && !is_array($callback)) {
- echo $callback('r'), PHP_EOL;
- } else if (is_array($callback)) {
- echo 'Handling ', $callbacktype, ' via call_user_func', PHP_EOL, call_user_func($callback, 'r'), PHP_EOL;
- }
- }
- $string = 'date';
- examineCallbacks('Invokable', $invokable);
- examineCallbacks('Closure', $function);
- examineCallbacks('String', $string);
- examineCallbacks('Array', $funcarray);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement