Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130134 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id 1E5B61A00BC for ; Mon, 23 Feb 2026 11:20:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1771845641; bh=g2WFPR0+N2KyGx8WW2Q0Jx+ym6wc6RDuRq5QbjtpnBU=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=hFo5hY2pCa5thQsG231Pg6gvIx9rfSLuGobgYpgQAAJYp/EGip5gfptG65VZ0zxOm ll2JIHPAv1JftbZ0FxL0AHdhe0x8QlDuDMOM2wx+4Jx3cI42wvw7gYQjeYi0k+IKWw B7c0tWqu+6j8cIM+/oQSZztDJdsuu8J3xzNSzddHr8amW/M40Cx2+B4lNLE4AE9VNy yQ9cZfDFIqDsYpkuRGyRW0VjPXZoIgEJjRsdsrG64ferznZxMDWJysd1AwK8knS4or ROopxm1iBtBWSZW7w1z/6vU/K1vF/+CZvMpMT/7cwgDQEHvdmLgqFOPOBjyMIWaux1 OgjGb5OiVlt/g== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C694118006D for ; Mon, 23 Feb 2026 11:20:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_50, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS, FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-oo1-f50.google.com (mail-oo1-f50.google.com [209.85.161.50]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 23 Feb 2026 11:20:40 +0000 (UTC) Received: by mail-oo1-f50.google.com with SMTP id 006d021491bc7-6786b13984fso2772701eaf.2 for ; Mon, 23 Feb 2026 03:20:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1771845635; cv=none; d=google.com; s=arc-20240605; b=AjFsKxYkafx6AC27x7oR6PkFfbNwXsj2ivuziV+MoQmLu9ER0p8SGMqsVGC2pPp389 Co2oP+g7eE7DHG4yA0gDZU6EqykSrhwTfBcsWfC8FANS9qXKOrcmGF+uRlTK12hAWlG3 VEZ4KwiwHAMKLsYV7VOuv5W4a2sPquIVcYe84L4HdhXO/Tkx0PQWurnPl4viUfA/RUNb iA//KUaP59oNqPjsxCTDq9LIBNP//n/UUSjLRJT52Y/gmRtRbXuOnO3k26NAkneEiArZ OY9khClgKdzWCbNoxFgpUhwzuTXQbfh2wNIeho6JML7twpExDi4dBSKftz02qsteUw3p +G9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=q3g+g879zyAiBQ7lsqr3IC/20x3KzOIB61bRDLetShg=; fh=/QqIYBxWPMfzobmoEhgo89HBWa9WX4gciiNMRpFCuwM=; b=PlJx/+vghqmkrCfbdWlRNMFYB1wcw6CYjSihT1xm0fJ69UFQjW3aeDZfb8e2FqmAT2 WX+f7fKSkIDYOrFajljOfveYICCxoXTi3bxcczLSJfUMOYrgByV68cwbaw1/Wu477t19 S5+hHP+zyVhGdGK+8YOZsDGDaGNexDrRRawHAxdjt/w+v0a1sSG+p5oXXFwz5gxZNeMg rWZ/9PdETiOvwGy1+kFk/YfN+EdUnzEVxTkaIcb0KwHjI9yx+3gzLC7NpC4AdjBamG2n 67O7dVgQqGZryzvrMKV9vOluGKffGMMK+QacnMiep98LgyFtrRVpoD4IcpVC97D/lWQh bM0w==; darn=lists.php.net ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771845635; x=1772450435; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=q3g+g879zyAiBQ7lsqr3IC/20x3KzOIB61bRDLetShg=; b=Xmepm5bAKWjNkviSIOYGdbceALVztLG3dK/lw8JdAAJqIYo06lbQBQ9yIDKh8E7eOf ppNrUYAb4KL9vVjH+I9BTj7JOsMvNfb4H4Ov/oH0w48F+fHQNpJxqp5XQ/B7K89KTDr7 ayYNdY2reeeHCdzKmbdvWxRd16Mo8R5JEGzFivYB5GwaRoDIDeCWGhNrbNT6XYy+of/e YCX7coi7/4QEMkY1lY8aGkyt7mvARalWCc5RH8c9HqWkDVXcXBvYkRXv/8onZFbGTzrx rgg5vancb7mIDo9uPTzYsCedPEGxTek7K6fIhT2/BRyEUlUdY42lou8pZbtqSBzVoEYc Dg2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771845635; x=1772450435; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=q3g+g879zyAiBQ7lsqr3IC/20x3KzOIB61bRDLetShg=; b=och5ao57KGFM8CThCVleNx0ulj6+QlE3CtEVewBGmpmCkS1fY8B51eWf3OmVX/BzAP mQChiRyZ80xQu9gs5ZX4u+YkX1YY6bd++VarSmEOF5wDjeRPPKHjy3upVKr/sBYW3af2 vWvCD59f4SfB6JILEoIErsxhCPZLxbfhLvM0666nohMAgGQ7iGYYUSHfKpAHoXisI7NT bTMHgQkL+CgHyNbs11KkaFDm8RyWVb3w1l3gtFbaosrrDgT+nENhDwZ39Hwljd+lGZw0 Tryluh/WLCsEX/PvOBfDKCMbRZJYgGIdT9cZDXwevs29mFS2eH4IYZgaiV8H42tNzwEc QwdA== X-Forwarded-Encrypted: i=1; AJvYcCVfqCjsgPcw6vohwIkv90w3pjkYxrkc0IGebfRlK9yitD7Nn9+5YN1n++OjkJR/JSCcNqB1nMxUP58=@lists.php.net X-Gm-Message-State: AOJu0YzAslOahuBC4BnRw0mtj+r3sGa8oX2d/WgGqRYCPSuWn0LRWKOB WfDDAgks5tyBIVSuJbbNVM0jU5YZj0APTAlUUunfoE6Kz4B2gaYCemS3MYpTVGR0zd7Ngbz3Vsm pVgC2oYLZmlQDQnVH6CiqID2BhK97Of1LOQ== X-Gm-Gg: AZuq6aJiamoH4n99me+qEWSuFVJTAauMwR+VhH5pzfzhAl0/mQhJ4S0Ym7jnhXp98MY KcbzOxskC1hkJB5Sto8+la4QpT2ylV3koZtJGCBskFaLSuajB0YQm6cl6lNN/CLa9lKePQ9XGiT PQojFwC+Hpcu6cMaI44uPSV+H20IQOdcETiYzKF3pkscCg3dySgQbXMCRhSYhTvzSmWbzsn+SSc MODK69PAwgRQTHKT1QNJ4BiMT9Nk6qYDJlREq8k3RIndmvGZ5fz873Vu/qxMaAQ8Uahp6Ds/b0S 9KjNaIrfOVExXTNnL7oghcGnvZNwnc/ItYQQASB+hq8iqbA4CZGwhs5xohOqQRcfr4gAZA== X-Received: by 2002:a05:6820:a03:b0:663:a85:25e8 with SMTP id 006d021491bc7-679c4662d9fmr4942705eaf.17.1771845634717; Mon, 23 Feb 2026 03:20:34 -0800 (PST) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: <1f25d77e-224b-40d6-bf19-18dfdfc9de54@rwec.co.uk> <453bc043-b4ee-423e-9561-55510f5c20a7@rwec.co.uk> <6412E222-9B0F-4139-A6F9-7D0C686197BF@rwec.co.uk> <88259C1D-1D31-4FB1-8CA8-1F704378467D@rwec.co.uk> In-Reply-To: Date: Mon, 23 Feb 2026 18:20:25 +0700 X-Gm-Features: AaiRm51Q-Ev8dMdu7tPjbRNXI7jFX_dtagBM1Bw3bEsvFbAI3cod_cM_1MM5gA4 Message-ID: Subject: Re: [PHP-DEV] [IDEA for RFC] let the "new" operator fail when the __construct() function returns a value. To: Mirco Babin Cc: "Rowan Tommins [IMSoP]" , PHP internals Content-Type: multipart/alternative; boundary="000000000000a77c3a064b7bf5b1" From: pierre.php@gmail.com (Pierre Joye) --000000000000a77c3a064b7bf5b1 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Feb 23, 2026, 4:23=E2=80=AFPM Mirco Babin w= rote: > 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 > wrote: > > >Failing early is not always possible. The compiler can not always infe= re > > >the correct return type. > > > > PHP defines "void" separately from "null", precisely so that the compil= er > > 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 --000000000000a77c3a064b7bf5b1 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable





On Mon, Feb 23, 2026, 4:23=E2=80=AFPM Mirco Babin <mirco.babin@gmail.com> wrote:
Op za 21 feb 2026 om 17:28 schreef Rowan Tommins [I= MSoP] <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", precise= ly so that the compiler
> doesn't need to infer anything about the returned value. All it ha= s to do
> is distinguish "return;" from "return some_expression;&= quot;
>
> Example: https://3v4l.org/cTaBP
>

That is a very good find. Are the following claims correct?


=C2=A0 =C2=A0In all cases it would be a compile error, because the compiler= only
=C2=A0 =C2=A0checks "return something;" vs. "return;".<= br>
=C2=A0 =C2=A0It would never throw a TypeError at runtime.

that's correct,=C2= =A0 as the return statement will have an expression, it will be detected.

absence of return is equi= valent to return; as well.=C2=A0

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.=C2=A0 the eng= ine 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 usuall= y done.


best,
--
Pierre

@pierrejoye | http://www.libgd.org
--000000000000a77c3a064b7bf5b1--