Re: [RFC] [DISCUSSION] Allow void return type for constructors/destructors

From: Date: Wed, 17 Jun 2020 13:53:20 +0000
Subject: Re: [RFC] [DISCUSSION] Allow void return type for constructors/destructors
References: 1 2 3 4 5 6 7  Groups: php.internals 
Request: Send a blank email to internals+get-110630@lists.php.net to get a copy of this message
Hey Christian, Wrong wording, sorry! :) > But I definitely wouldn't want a deprecation warning for constructors without explicit > ': void' as I see no reason to force people to use it. This RFC proposes 2 things: 1) If a non-void value is returned from a constructor/destructor, a deprecation warning is thrown. Meanwhile, in PHP 9.0 a fatal error is thrown instead. 2) It will be allowed to declare constructors/destructors explicitly as : void (previously this was illegal). Best regards, Benas On Wed, 17 Jun 2020 at 16:36, Christian Schneider <cschneid@cschneid.com> wrote: > > Am 17.06.2020 um 13:59 schrieb Benas IML <benas.molis.iml@gmail.com>: > > We should allow newer codebases to enforce void rules on > > constructors/destructors by allowing to explicitly declare return type as > > void. > > I don't see a big benefit in this explicit return type void as newer codebases hopefully > will try to get rid of deprecation warnings and thus fixing it but if you think this is helpful then > I'll shut up :-) > > > Meanwhile, we should throw a deprecation warning, if the constructor/destructor is > > returning a non-void value and doesn't have an explicit : > > void declaration. > > I'm not sure I understand the second part "and doesn't have an explicit > : void declaration". > If there is a ' : void' declaration then returning any value will be an error. > As far as I can see this is already the case: > php -r 'class A { function __construct() : void { return 42; } }' > with PHP 7.4 gives > PHP Fatal error: A void function must not return a value in Command line code on line 1 > > But I definitely wouldn't want a deprecation warning for constructors without explicit > ': void' as I see no reason to force people to use it. > > > Then, presumably in PHP 9, in addition to explicit : void, > > also enforce void rules implicitly > > altogether. > > Yes, that's how I would do it. > > - Chris >

« previous php.internals (#110630) next »