Re: [RFC] noreturn type

From: Date: Mon, 29 Mar 2021 17:25:15 +0000
Subject: Re: [RFC] noreturn type
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-113853@lists.php.net to get a copy of this message
Hi Matthew

> 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 for the RFC! I'm very much in support of it.

Two small things:

1. Some magic methods like __toString currently require a specific
return type (like string in that case). Since noreturn is a bottom
type technically it should be possible to type hint those magic
methods with noreturn. It's not a big issue if that's not possible,
but it should be mentioned in the RFC.

2. noreturn is one of the few return types that would technically make
sense for __construct (other than void).

class Foo {
    public function __construct(): noreturn {
        throw new Exception();
    }
}

new Foo();
bar(); // < Dead code

Not sure this is worth supporting but I just wanted to mention it.

Ilija


Thread (37 messages)

« previous php.internals (#113853) next »