Re: [IDEA for RFC] let the "new" operator fail when the __construct() function returns a value.

From: Date: Mon, 09 Feb 2026 09:29:55 +0000
Subject: Re: [IDEA for RFC] let the "new" operator fail when the __construct() function returns a value.
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-130062@lists.php.net to get a copy of this message
> FYI/Just in case anyone already wants to forbid this - there is a sniff > available which will flag both constructors as well as destructors with > a return type and/or when the function returns something: > Universal.CodeAnalysis.ConstructorDestructorReturn > > Ref: > https://github.com/PHPCSStandards/PHPCSExtra#universalcodeanalysisconstructordestructorreturn-wrench-books Thank you very much for this information. Using PHP Code Sniffer, we identified two more return values from the __construct() functions. Installing PHP Code Sniffer on Windows without using Composer is cumbersome. For those who want to use the PHP Code Sniffer tool, I've included installation instructions in the original issue, see: https://github.com/php/php-src/issues/21090#issuecomment-3870404274 Kind regards, Mirco Babin Op za 7 feb 2026 om 00:56 schreef Juliette Reinders Folmer <php-internals_nospam@adviesenzo.nl>: > > On 6-2-2026 20:59, Tim Düsterhus wrote: > > On 2/2/26 19:00, Mirco Babin wrote: > > # RFC > > I've been asked to follow the RFC process. And I've been told that the > rejected PHP RFC Make constructors and destructors return void > ( https://wiki.php.net/rfc/make_ctor_ret_void ) rejects my > proposal. > However, my proposal is explicitly about the "new" operator and not > about return types. It does, however, concern return values. > > > Personally I find the fact that it's illegal to define a return type on > __construct() to be a pretty good indication that the constructor is > not meant to be able to return anything. As such I'm a little surprised by the disagreement in > that RFC, though it should be noted that a majority was in favor (just not a 2/3's majority). > > > FYI/Just in case anyone already wants to forbid this - there is a sniff available which will > flag both constructors as well as destructors with a return type and/or when the function returns > something: Universal.CodeAnalysis.ConstructorDestructorReturn > > Ref: ’ �÷_à8@Ù > ™jsªôòhttps://github.com/PHPCSStandards/PHPCSExtra#universalcodeanalysisconstructordestructorreturn-wrench-books

« previous php.internals (#130062) next »