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

From: 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:
So, if you call $object->__construct(), there's no error, and you can get the return value, but if you do new Foo(), you'd get an error?
That is correct.
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:
    function foo(): void {
        return 1;
    }
    // Fatal error: A void function must not return a value
Best regards Tim Düsterhus

« previous php.internals (#130037) next »