<?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();
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_closure = $callable instanceof \Closure;
if ($is_callable === true) {
/** @noinspection VariableFunctionsUsageInspection */
Example::typeHintCallable($callable);
}
if ($is_closure === true) {
Example::typeHintClosure($callable);
}
if ($is_invoke === true) {
$callable('foo');
}
'key' => $key,
));
});
PD9waHAKCm5hbWVzcGFjZSBQb3RoZXJjYVxFeGFtcGxlXFR5cGVIaW50czsKCmNsYXNzIEV4YW1wbGUKewogICAgcHVibGljIHN0YXRpYyBmdW5jdGlvbiB0eXBlSGludE1pc3NpbmcoJHN1YmplY3QpCiAgICB7CiAgICAgICAgcmV0dXJuICRzdWJqZWN0OwogICAgfQoKICAgIHB1YmxpYyBzdGF0aWMgZnVuY3Rpb24gdHlwZUhpbnRDYWxsYWJsZShjYWxsYWJsZSAkc3ViamVjdCkKICAgIHsKICAgICAgICByZXR1cm4gJHN1YmplY3Q7CiAgICB9CgogICAgcHVibGljIHN0YXRpYyBmdW5jdGlvbiB0eXBlSGludENsb3N1cmUoXENsb3N1cmUgJHN1YmplY3QpCiAgICB7CiAgICAgICAgcmV0dXJuICRzdWJqZWN0OwogICAgfQoKICAgIHB1YmxpYyBmdW5jdGlvbiBfX2ludm9rZSgkc3ViamVjdCkKICAgIHsKICAgICAgICByZXR1cm4gJHN1YmplY3Q7CiAgICB9Cn0KCiRvdXRwdXQgPS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