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.
43 lines
915 B
43 lines
915 B
--TEST--
|
|
Symfony pattern: nullable callable converted to first-class callable
|
|
--FILE--
|
|
<?php
|
|
|
|
class SymfonyLikeInput
|
|
{
|
|
private ?Closure $onEmpty = null;
|
|
private array $input = [];
|
|
|
|
public function onEmpty(?callable $onEmpty = null): void
|
|
{
|
|
$this->onEmpty = null !== $onEmpty ? $onEmpty(...) : null;
|
|
}
|
|
|
|
public function write(string $value): void
|
|
{
|
|
$this->input[] = $value;
|
|
}
|
|
|
|
public function next(): ?string
|
|
{
|
|
if (!$this->input && null !== $onEmpty = $this->onEmpty) {
|
|
$this->write($onEmpty($this));
|
|
}
|
|
|
|
return array_shift($this->input);
|
|
}
|
|
}
|
|
|
|
function main(): void
|
|
{
|
|
$stream = new SymfonyLikeInput();
|
|
$stream->onEmpty(static fn (SymfonyLikeInput $input): string => 'generated');
|
|
var_dump($stream->next());
|
|
|
|
$stream->onEmpty(null);
|
|
var_dump($stream->next());
|
|
}
|
|
?>
|
|
--EXPECT--
|
|
string(9) "generated"
|
|
NULL
|
|
|