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

From: Date: Mon, 23 Feb 2026 16:56:00 +0000
Subject: Re: [IDEA for RFC] let the "new" operator fail when the __construct() function returns a value.
References: 1 2 3 4 5 6 7 8 9 10 11  Groups: php.internals 
Request: Send a blank email to internals+get-130137@lists.php.net to get a copy of this message
hi Mirco, On Mon, Feb 23, 2026, 11:00 PM Mirco Babin <mirco.babin@gmail.com> wrote: > Hello Pierre, > > Op vr 20 feb 2026 om 19:29 schreef Pierre Joye <pierre.php@gmail.com>: > > > > Hello Mirco, > > > > > In a context of __construct, disallow any return value can be detected > > as well. Any return statement with anything used with it can be > > rejected (and should). > > > > It is documented as void, we could "fix" it with a bug fix. > > - > https://www.php.net/manual/en/language.oop5.decon.php#object.construct > lists the __construct() function as void. > - But the implementation of __construct() is mixed. > > l > see https://www.php.net/manual/en/language.oop5.decon.php __construct(mixed <https://www.php.net/manual/en/language.types.mixed.php> ...$values = ""): void <https://www.php.net/manual/en/language.types.void.php> > I have found > https://php-legacy-docs.zend.com/manual/php4/en/migration5. > But I didn't find any specific __construct() instructions, other than > > https://php-legacy-docs.zend.com/manual/php4/en/language.oop5.decon. > At > that page, it is not mentioned the __construct() must not return a value. > it should I think, maybe it was not done for bc or avoid breaking codes, but it was years ago. > Could you explain on serialization or hydration challenges in more > details? Perhaps with a theoretical example? > An (old) real-world example would be even better, if you can find one. > Sorry, i do not have the time to look. Try to google a bit, quite a lot of old bugs in various projects about that. Best, >

« previous php.internals (#130137) next »