TypePHP 编译器 https://swoole.com/aot/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

35 lines
755 B

--TEST--
Symfony pattern: dynamic first-class callable branch
--FILE--
<?php
final class CallableTarget
{
public function format(string $value): string
{
return 'object:'.strtoupper($value);
}
}
function format_global(string $value): string
{
return 'function:'.strtolower($value);
}
function makeCallable(array $callable): Closure
{
return $callable[0] ? $callable[0]->{$callable[1]}(...) : $callable[1](...);
}
function main(): void
{
$objectCallable = makeCallable([new CallableTarget(), 'format']);
$functionCallable = makeCallable([null, 'format_global']);
var_dump($objectCallable('symfony'));
var_dump($functionCallable('AOT'));
}
?>
--EXPECT--
string(14) "object:SYMFONY"
string(12) "function:aot"