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

From: Date: Fri, 06 Feb 2026 23:53:37 +0000
Subject: Re: [IDEA for RFC] let the "new" operator fail when the __construct() function returns a value.
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-130043@lists.php.net to get a copy of this message
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: https://github.com/PHPCSStandards/PHPCSExtra#universalcodeanalysisconstructordestructorreturn-wrench-books

« previous php.internals (#130043) next »