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

From: Date: Mon, 23 Feb 2026 11:20:25 +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-130134@lists.php.net to get a copy of this message
On Mon, Feb 23, 2026, 4:23 PM Mirco Babin <mirco.babin@gmail.com> wrote: > Op za 21 feb 2026 om 17:28 schreef Rowan Tommins [IMSoP] < > imsop.php@rwec.co.uk>: > > > > On 20 February 2026 16:07:01 GMT, Mirco Babin <mirco.babin@gmail.com> > wrote: > > >Failing early is not always possible. The compiler can not always infere > > >the correct return type. > > > > PHP defines "void" separately from "null", precisely so that the > > compiler > > doesn't need to infer anything about the returned value. All it has to do > > is distinguish "return;" from "return some_expression;" > > > > Example: https://3v4l.org/cTaBP > > > > That is a very good find. Are the following claims correct? > > > In all cases it would be a compile error, because the compiler only > checks "return something;" vs. "return;". > > It would never throw a TypeError at runtime. that's correct, as the return statement will have an expression, it will be detected. absence of return is equivalent to return; as well. you can see it using the ast extension, that may help you to see what can or cannot be check at compile vs runtime, I general. the engine does many compile time checks but not as much as a static analyzers or a compiled language can do, but things similar to this are cheap and usually done. best, -- Pierre @pierrejoye | http://www.libgd.org

« previous php.internals (#130134) next »