Re: [RFC] noreturn type

From: Date: Fri, 12 Mar 2021 04:10:47 +0000
Subject: Re: [RFC] noreturn type
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-113492@lists.php.net to get a copy of this message

> On Mar 10, 2021, at 12:06 PM, Matthew Brown <matthewmatthew@gmail.com> wrote:
> 
> Hey,
> 
> Ondřej Mirtes and I present an RFC for the noreturn type:
> https://wiki.php.net/rfc/noreturn_type
> 
> The feature already exists in Hack (the primary inspiration) and is
> currently supported by our static analysis tools inside docblocks, and we
> feel there's a good argument for it to be supported by PHP itself.
> 
> Thanks,
> 
> Matt & Ondřej


Hi Matt & Ondřej,

I wanted to give my +1 to this proposal.

I was curious to see how fibers might interact with this declaration, since it is possible to create
a fiber that can not return. So, I compiled your branch and gave it a try.

```
$fiber = new Fiber(function (): noreturn {
    while (true) {
        Fiber::suspend(\random_int(0, 100));
    }
});

$result = $fiber->start();

for ($i = 0; $result; ++$i) {
    echo $result, "\n";
    $result = $fiber->resume();
}

echo "Generated ", $i, " numbers before generating zero.\n";
```

This short script works just as expected, cool! :-D

Cheers,
Aaron Piotrowski


Thread (37 messages)

« previous php.internals (#113492) next »