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

From: Date: Tue, 17 Feb 2026 06:59:43 +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-130079@lists.php.net to get a copy of this message
>Hi Mirco, and welcome! > >I agree that allowing constructors to return a value leads to confusion, >and would support deprecating and then forbidding this. > >However, I agree with others that this should be checked when compiling >the constructor, not when running it under the "new" operator. In other >words, make any method named "__construct" give >the same error as a >function or method marked ": void". Hello Rowan Tommins, I disagree with the compiling part. The __construct() function can currently not have a return type, so the return type is implicitly "mixed". Changing that would be a BC break for those calling the __construct() function as a regular function. As written to Tim Düsterhus: I have prepared a RFC at https://gist.github.com/MircoBabin/aaa574297c8d1baa879f19c99ce28e93 Kind regards, Mirco Babin

« previous php.internals (#130079) next »