Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130101 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 9F30F1A00BC for ; Fri, 20 Feb 2026 07:41:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1771573294; bh=CXs0PJ6l1cYepsCbjPUjCG5ko1b15oaUxdmpPOVDAKo=; h=Date:From:To:Subject:In-Reply-To:References:From; b=gy6TIM3PYqSQQd41bCcoqLyckE3SUywgqC771xN6iP4rGUnQXUsw3g7KkwbdFc6X7 iT/YARvlQd9MVVaU2PKZ95oCE32kuGODQYRcglSHtnV5r3MlcUu+S1TkchRxDXRgZ6 fzmYs73FVclTlBm+Fvd6aZcByWAhRKpxOPW8OrUcWH9acZ13M6yxvH8M2MXeINcFu2 lP/lUO+6xGj6GxCQVzn0TKEi1IkpEwtRstsMzAVuL/BIRRTXwTtYeVv6dMVccboFDD kvrr7n/ze0kxjDfAQxOe4ddVhFg1SlHnDMorzskEjw7cPh1C8oSeKN5jLjIhnIt6/M ArlAxcN9K768A== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 47CC31801E7 for ; Fri, 20 Feb 2026 07:41:33 +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.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from fhigh-a3-smtp.messagingengine.com (fhigh-a3-smtp.messagingengine.com [103.168.172.154]) (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 ; Fri, 20 Feb 2026 07:41:22 +0000 (UTC) Received: from phl-compute-07.internal (phl-compute-07.internal [10.202.2.47]) by mailfhigh.phl.internal (Postfix) with ESMTP id A3FE2140019C for ; Fri, 20 Feb 2026 02:41:17 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Fri, 20 Feb 2026 02:41:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rwec.co.uk; h=cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1771573277; x=1771659677; bh=5t9sSozDx4SmvXP97795m7kKlmoI0D6Tdxn/5SdN7VM=; b= a4sSdosMPHe9/4xKfGbhFSyF9h5YaH05jng+8XrO2BL35uy/fj630Iu4r38+hnbd Adit5ex64swxtYRdvfP/EutHrQ7unAEzqNF498pb/at8ShD4Rzrf810PslFfhmnD OajYhxdSZZuu+GCYEuTMVwoIWvbG+KX64Y+49oiTOWk5vJF1NiSEtR5y7yzb9eUN 92snd+mFOXUYPpZTr6ZQSaFd/lqB4sBkC85HgZ+J6tNDS+zPeaCY/OWQ+4lejz8W IliaFN0cPQ6cT5a0gIdV7EWG6bBSoP7nvdFvTyZfrszOqJLKMbnk1zwoRHtZwLQX OI0fIjM4a/8J5VJEI08WQA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1771573277; x=1771659677; bh=5 t9sSozDx4SmvXP97795m7kKlmoI0D6Tdxn/5SdN7VM=; b=SCU3DcH0V3DzEssHe DT+6grfZ4de6Av1zTsHhi6dQpC+ejbjRZNLyIdkLsnfXqn+rQ4FeykMyysN/Ytet Jd718QD83SsRi1lDH2D+INfq2pLcXAveusyPTOfEkx/8VXzPkPJkhvH48VPM9lbT 21fWDvcG5z1hkzYnMbcS3hukkdMD7W+0jk91B/NTItrwdHgCPAfjipDlzTVvgWF0 9gGzwPQVJvh7z0lsbbRiAmSV7hfd+kBwWXgjISVUww+SN5uvkUXZA8vhYbCfaYVh 8dOWH/rbVdJcI0gaX1djjakH3Xq5UU0LDsu2ZLCRinYDQSgqTQC3j7NT+J02vVw7 Qvktg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddvvdejkeehucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucenucfjughrpeffhffvufgfjghfkfggtgfgsehtqhhmtd dtreejnecuhfhrohhmpedftfhofigrnhcuvfhomhhmihhnshculgfkoffuohfrngdfuceo ihhmshhophdrphhhphesrhifvggtrdgtohdruhhkqeenucggtffrrghtthgvrhhnpeehle ffteeigfevudetfedugedtudevledugeeugeelheeihfehgfdtkeevvefgleenucevlhhu shhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehimhhsohhprdhphh hpsehrfigvtgdrtghordhukhdpnhgspghrtghpthhtohepuddpmhhouggvpehsmhhtphho uhhtpdhrtghpthhtohepihhnthgvrhhnrghlsheslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 20 Feb 2026 02:41:16 -0500 (EST) Date: Fri, 20 Feb 2026 07:40:14 +0000 To: internals@lists.php.net Subject: =?US-ASCII?Q?Re=3A_=5BPHP-DEV=5D_=5BIDEA_for_RF?= =?US-ASCII?Q?C=5D_let_the_=22new=22_operator_?= =?US-ASCII?Q?fail_when_the_=5F=5Fconstruct=28?= =?US-ASCII?Q?=29_function_returns_a_value=2E?= User-Agent: K-9 Mail for Android In-Reply-To: References: <1f25d77e-224b-40d6-bf19-18dfdfc9de54@rwec.co.uk> <453bc043-b4ee-423e-9561-55510f5c20a7@rwec.co.uk> Message-ID: <6412E222-9B0F-4139-A6F9-7D0C686197BF@rwec.co.uk> Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") On 19 February 2026 20:24:56 GMT, Mirco Babin w= rote: >> That's a different kind of "why"=2E I meant, "why would a programmer >> deliberately call a function __construct, and have no intention of >> *ever* using it as a constructor"=2E > >A theoretical example can be found in >"Unaffected calling the parent constructor example"=2E >UnaffectedBaseClass could be abstract=2E > >```php >class UnaffectedBaseClass >{ > public function __construct() > { > return ['important']; > } >} > >class UnaffectedCallParentConstructor extends UnaffectedBaseClass >{ > public function __construct() > { > $important =3D parent::__construct(); > } >} > >$it =3D new UnaffectedCallParentConstructor(); >``` In that example, the method on UnaffectedBaseClass can not be used as a co= nstructor under your proposal=2E As such, it's just a normal method which c= an be trivially renamed:=20 ``` class UnaffectedBaseClass { public function initialise() { return ['important']; } } class UnaffectedCallParentConstructor extends UnaffectedBaseClass { public function __construct() { $important =3D parent::initialise(); } } $it =3D new UnaffectedCallParentConstructor(); ``` >> If they are using it as *both* a constructor and a normal method, >> *their code will break with your proposal* because at some point >> they will call it as a constructor and hit the new error=2E > >Not necessarily=2E When an if is used, __construct() can be either=2E True=2E I'm not convinced the language should bend over backwards to suppo= rt such a pattern, though=2E >The Php scripting aspect makes it difficult in general >for untyped projects to fail early=2E=20 This is a completely irrelevant statement=2E We're not talking about faili= ng early "in general", we're talking about a compile-time check that PHP al= ready makes in other contexts=2E >> The only difference that delaying the error to run-time makes, is that >> it will take longer for people to notice that it is broken=2E > >Not necessarily true=2E Assume the code is running fine on a shared hosti= ng >platform with Php 8=2E5=2E Then the hosting provider decides to force an >update to Php 9, because of a critical vulnerability=2E That same code >would then break at some point=2E=20 I don't see how this contradicts what I said=2E Instead of it failing imme= diately, it fails "at some point" - so, it will take longer to happen=2E Yo= u consider that a good thing, I consider it a bad thing; I guess we're not = going to convince each other on that=2E >I assume the spaghetti contains some version of my two theoretical >examples=2E > >So it is safer to *not* make the return type declaration implicitly "void= "=2E The way I see it, we have to draw the line somewhere regarding what use of= "__construct" methods is "acceptable", and what use we're going to force u= sers to fix=2E There are three options on the table:=20 1) You may return any value, the "new" operator will silently discard it [= current behaviour] 2) You must not return a value 3) You may return a value in the definition, but must make sure that no us= es of the "new" operator reach that return statement I find option 3 unnecessarily complicated=2E Faced with an existing code b= ase, checking and fixing violations of option 2 seems a lot easier than kee= ping the return values but making sure they won't error under option 3=2E I think that either we should add a simple, easily checked, rule - option = 2; or we should avoid breaking people's code, and retain option 1=2E Regards, Rowan Tommins [IMSoP]