Re: [IDEA for RFC] let the "new" operator fail when the __construct() function returns a value.
| From: | Tim Düsterhus | Date: | Fri, 06 Feb 2026 20:02:03 +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-130037@lists.php.net to get a copy of this message | ||
Hi
On 2/5/26 18:40, Mirco Babin wrote:
As mentioned in my other email, I believe it should just be an error either way. In fact I would expect the result to be quite similar to how it already is a compile-time (!) error to return something from a void function:So, if you callThat is correct.$object->__construct(), there's no error, and you can get the return value, but if you donew Foo(), you'd get an error?
function foo(): void {
return 1;
}
// Fatal error: A void function must not return a value
Best regards
Tim Düsterhus