On Fri, Mar 19, 2021 at 3:45 PM Marco Pivetta <ocram...@gmail.com> wrote:
> Hey Nikita, > > On Fri, Mar 19, 2021, 14:35 Nikita Popov <nikita....@gmail.com> wrote: > >> >> Is it allowed to declare a noreturn function that returns by reference? >> >> function &foo(): noreturn {} >> > > Given that `noreturn` means it should throw, loop forever or exit, how > would a by-ref usage be applied/useful? > > Or is it a hint at a missing test? > Mainly a hint for missing spec ;) Context is that we're considering to deprecate by-ref void return ( https://wiki.php.net/rfc/deprecations_php_8_1#return_by_reference_with_void_type), so it would make sense to me to prohibit this for noreturn from the start. However, I could also see an argument for why allowing it may be useful due to variance considerations. It would allow you to write something like this: <?php class A { public function &test(): int { ... } } class B extends A { public function &test(): noreturn { throw new Exception; } } While dropping the by-ref return on B::test() would be forbidden by variance (and I don't think we'd want to add more special rules here, like ignoring ref-return variance for noreturn functions). Regards, Nikita