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

From: Date: Mon, 23 Feb 2026 16:00:06 +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  Groups: php.internals 
Request: Send a blank email to internals+get-130136@lists.php.net to get a copy of this message
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. > > Also, about this whole discussion , that __ construct, can still be > called as a normal method. Some relics of php 4-5 migration path and > then work around serialization or hydration challenges. > > Most maintained projects out there moved away from these hacks and > rely on new reliable solution for these challenges, like doctrine > or symfony serializer. 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. 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. Kind regards, Mirco Babin

« previous php.internals (#130136) next »