@ 2017-11-14T11:49:00Z <?php
namespace Potherca\Example\TypeHints;
class Example
{
public static function typeHintMissing($subject)
{
return $subject;
}
public static function typeHintCallable(callable $subject)
{
return $subject;
}
public static function typeHintClosure(\Closure $subject)
{
return $subject;
}
public function __invoke($subject)
{
return $subject;
}
}
$output = <<<'TXT'
================================================================================
(%d) %s : %s
callable : %s
__invoke : %s
closure : %s
TXT;
$example = new Example();
$callables = array(
1 => 'foo',
2 => 'trim',
3 => '\Potherca\Example\TypeHints\Example::typeHintMissing',
4 => array('\Potherca\Example\TypeHints\Example', 'typeHintMissing'),
5 => array($example, 'typeHintMissing'),
6 => $example,
7 => function ($subject) {return $subject;},
);
array_walk($callables, function ($callable, $key) use ($output) {
$is_callable = is_callable($callable);
$is_invoke = method_exists($callable, '__invoke');
$is_closure = $callable instanceof \Closure;
if ($is_callable === true) {
/** @noinspection VariableFunctionsUsageInspection */
call_user_func($callable, 'foo');
Example::typeHintCallable($callable);
}
if ($is_closure === true) {
Example::typeHintClosure($callable);
}
if ($is_invoke === true) {
$callable('foo');
}
vprintf($output, array(
'key' => $key,
'type' => gettype($callable),
'value' => str_replace(array("\n", ' '), '', var_export($callable, true)),
'is_callable' => var_export($is_callable, true),
'is_invoke' => var_export($is_invoke, true),
'is_closure' => var_export($is_closure, true),
));
});
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.4.1 - 8.4.12 ================================================================================
(1) string : 'foo'
callable : false
__invoke : false
closure : false
================================================================================
(2) string : 'trim'
callable : true
__invoke : false
closure : false
================================================================================
(3) string : '\\Potherca\\Example\\TypeHints\\Example::typeHintMissing'
callable : true
__invoke : false
closure : false
Fatal error: Uncaught TypeError: method_exists(): Argument #1 ($object_or_class) must be of type object|string, array given in /in/jqMtg:54
Stack trace:
#0 /in/jqMtg(54): method_exists(Array, '__invoke')
#1 [internal function]: {closure:/in/jqMtg:51}(Array, 4)
#2 /in/jqMtg(51): array_walk(Array, Object(Closure))
#3 {main}
thrown in /in/jqMtg on line 54
Process exited with code 255 . Output for 8.2.0 - 8.2.29 , 8.3.0 - 8.3.25 ================================================================================
(1) string : 'foo'
callable : false
__invoke : false
closure : false
================================================================================
(2) string : 'trim'
callable : true
__invoke : false
closure : false
================================================================================
(3) string : '\\Potherca\\Example\\TypeHints\\Example::typeHintMissing'
callable : true
__invoke : false
closure : false
Fatal error: Uncaught TypeError: method_exists(): Argument #1 ($object_or_class) must be of type object|string, array given in /in/jqMtg:54
Stack trace:
#0 /in/jqMtg(54): method_exists(Array, '__invoke')
#1 [internal function]: Potherca\Example\TypeHints\{closure}(Array, 4)
#2 /in/jqMtg(51): array_walk(Array, Object(Closure))
#3 {main}
thrown in /in/jqMtg on line 54
Process exited with code 255 . Output for 8.0.0 - 8.0.30 , 8.1.0 - 8.1.33 ================================================================================
(1) string : 'foo'
callable : false
__invoke : false
closure : false
================================================================================
(2) string : 'trim'
callable : true
__invoke : false
closure : false
================================================================================
(3) string : '\\Potherca\\Example\\TypeHints\\Example::typeHintMissing'
callable : true
__invoke : false
closure : false
Fatal error: Uncaught TypeError: method_exists(): Argument #1 ($object_or_class) must be of type object|string, array given in /in/jqMtg:54
Stack trace:
#0 /in/jqMtg(54): method_exists(Array, '__invoke')
#1 [internal function]: Potherca\Example\TypeHints\{closure}(Array, 4)
#2 /in/jqMtg(79): array_walk(Array, Object(Closure))
#3 {main}
thrown in /in/jqMtg on line 54
Process exited with code 255 . Output for 5.4.0 - 5.4.45 , 5.5.0 - 5.5.38 , 5.6.0 - 5.6.30 , 7.0.0 - 7.0.25 , 7.1.0 - 7.1.20 , 7.2.5 - 7.2.33 , 7.3.16 - 7.3.33 , 7.4.0 - 7.4.33 ================================================================================
(1) string : 'foo'
callable : false
__invoke : false
closure : false
================================================================================
(2) string : 'trim'
callable : true
__invoke : false
closure : false
================================================================================
(3) string : '\\Potherca\\Example\\TypeHints\\Example::typeHintMissing'
callable : true
__invoke : false
closure : false
================================================================================
(4) array : array (0 => '\\Potherca\\Example\\TypeHints\\Example',1 => 'typeHintMissing',)
callable : true
__invoke : false
closure : false
================================================================================
(5) array : array (0 => Potherca\Example\TypeHints\Example::__set_state(array()),1 => 'typeHintMissing',)
callable : true
__invoke : false
closure : false
================================================================================
(6) object : Potherca\Example\TypeHints\Example::__set_state(array())
callable : true
__invoke : true
closure : false
================================================================================
(7) object : Closure::__set_state(array())
callable : true
__invoke : true
closure : true
Output for 5.3.0 - 5.3.29 ================================================================================
(1) string : 'foo'
callable : false
__invoke : false
closure : false
Catchable fatal error: Argument 1 passed to Potherca\Example\TypeHints\Example::typeHintCallable() must be an instance of Potherca\Example\TypeHints\callable, string given, called in /in/jqMtg on line 60 and defined in /in/jqMtg on line 12
Process exited with code 255 . Output for 4.4.2 - 4.4.9 , 5.1.0 - 5.1.6 , 5.2.0 - 5.2.17 Parse error: syntax error, unexpected T_STRING in /in/jqMtg on line 3
Process exited with code 255 . Output for 4.3.0 - 4.3.1 , 4.3.5 - 4.3.11 , 4.4.0 - 4.4.1 , 5.0.0 - 5.0.5 Parse error: parse error, unexpected T_STRING in /in/jqMtg on line 3
Process exited with code 255 . Output for 4.3.2 - 4.3.4 Parse error: parse error in /in/jqMtg on line 3
Process exited with code 255 . preferences:dark mode live preview ace vim emacs key bindings
157.19 ms | 419 KiB | 5 Q