Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130086 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 03DDD1A00BC for ; Tue, 17 Feb 2026 19:24:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1771356296; bh=bjivJVNdupi8Ngyo8/XLo9ZQiY1dtDZ5Rcnkm7ozd8k=; h=Date:Subject:To:References:From:In-Reply-To:From; b=emq+0i8TTU3kRiLcyGuAjFtWWsag7rF7davN1iX1O2PiLDVJ1apk3Hi/1234/NEkL GuF/7NpFlUgG4qNe8hmP6s3O7BvujBIIdMvKpgT9G72pT2Bzoz1oG1LsMlK7ycQ/u0 KFS9DW3ZB9JElV+5JL69wtiH9G6ZuMICq2t5vZdZKAO4707bHFa8ubfFQffq+0OM// 1+8jC7WSaZoLGKZIeKEoniORXl50jGCGyVI3xGP5Sa45Ur6xE/F2uS1coN6Ht7PO55 wCqBk/WckAf6SJ00nHJ5XG3n2WZLGRUBuYswCzuwkX+SsFs0QpfxxV2RLYrsCdiGXx E+GyiGizoousg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C8A3818004F for ; Tue, 17 Feb 2026 19:24:55 +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 fout-b2-smtp.messagingengine.com (fout-b2-smtp.messagingengine.com [202.12.124.145]) (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 ; Tue, 17 Feb 2026 19:24:55 +0000 (UTC) Received: from phl-compute-03.internal (phl-compute-03.internal [10.202.2.43]) by mailfout.stl.internal (Postfix) with ESMTP id 1E6591D00045 for ; Tue, 17 Feb 2026 14:24:50 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Tue, 17 Feb 2026 14:24:50 -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=1771356289; x=1771442689; bh=bkIPY/H+af17gUKVLr16JfWeP4wI3xrrqhOG570ypas=; b= eLxSqPxjMpH+l9BIZ20BdOTJaSfydYy4QS/MPAFflbMN9PMnENhMBo5cDkztfenx yHFfZHlEEqV91FQv9FX7vAnwIwQ2iWFi2JFm9OYbIuKwPrx/uinCN5/6MowbYQbM L9F5Uco+EJSvAsyanIubjgAPnKOjhqkNqhtQsNnujKs2ujkCTTF7RgpuZPTnSuqc ie0aJSSHaTCuIJIvDGq1+qGM0XeUftm06vZ+2eFwITTlxUJE/XYhk/22ybdRcFyR D+ccZxycmttABkTSTjrGK+BN/mpiwiKsWXjoH4J2eidGNNOnzUCttizRFVj/W775 dCbGZ1uYfC5kGSzFu96ijg== 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=1771356289; x=1771442689; bh=b kIPY/H+af17gUKVLr16JfWeP4wI3xrrqhOG570ypas=; b=tvRIyjhJ/1H06c6Ef fFASOkuZfQ+NuxRpAbCAK++DjEn1IT4X2MaXNlBW8aKDIrxB8CN1q1OlizbxO/Yk y+FJRXrNZHwQZQaUdI0VROef6ogl9xUHt1NJyX5Zy8wb3XsmGUv2j/YYfymqXBqN 6Rawlq84K4bob7P7WnBCGiVD98ecENHgpln/c9jzLgnW9+ACTY492h/w4vCfQFAw Wr6DVeqP/amH1RJgX0qcvhHLTDvvIFtsdmCg4VOorNIvJUjFNxkAtpASy5pUDn50 J0+NUhCvhZP/BtL9kMcluoqvyr8536eGCb2UdVmilOyqJC7VBsaIQzbtIvd+wyxR uElpA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddvvddtheelucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucenucfjughrpefkffggfgfuvfhfhfgjtgfgsehtkeertd dtvdejnecuhfhrohhmpedftfhofigrnhcuvfhomhhmihhnshculgfkoffuohfrngdfuceo ihhmshhophdrphhhphesrhifvggtrdgtohdruhhkqeenucggtffrrghtthgvrhhnpeffke evudffuddvheejvdefkeelfedtudegfeehjeduheegieduffeggeegveefheenucevlhhu shhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehimhhsohhprdhphh hpsehrfigvtgdrtghordhukhdpnhgspghrtghpthhtohepuddpmhhouggvpehsmhhtphho uhhtpdhrtghpthhtohepihhnthgvrhhnrghlsheslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 17 Feb 2026 14:24:49 -0500 (EST) Message-ID: <453bc043-b4ee-423e-9561-55510f5c20a7@rwec.co.uk> Date: Tue, 17 Feb 2026 19:24:47 +0000 Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] [IDEA for RFC] let the "new" operator fail when the __construct() function returns a value. To: internals@lists.php.net References: <1f25d77e-224b-40d6-bf19-18dfdfc9de54@rwec.co.uk> Content-Language: en-GB In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") On 17/02/2026 06:59, Mirco Babin wrote: > I disagree with the compiling part. The __construct() function can > currently not have a return type, so the return type is implicitly > "mixed". Changing that would be a BC break for those calling the > __construct() function as a regular function. It's a BC break either way - which is fine, if it only happens in PHP 9.0. Consider this example in your draft RFC: ``` class UnaffectedBaseClass {     public function __construct()     {         return ['important'];     } } ``` Right now, there is nothing stopping someone calling that constructor as `new UnaffectedBaseClass`. In PHP 9.0, that working code will become an error - a BC break. This is true even if the class is marked `abstract`: ``` abstract class AbstractBaseClass {     public function __construct()     {         return ['important'];     } } class ValidSubClass extends AbstractBaseClass { } $it = new ValidSubClass(); // Error in PHP 9.0 ``` In fact, the only way to guarantee a class is unaffected would be to write a method called "__construct", but then use static analysis to prove that nothing actually uses that method as a constructor. In which case, why use the reserved name "__construct"? My suggestion is that classes which are affected should show an error *as soon as possible*, so that users are prompted to fix the definition. In the example above, I would much prefer to see the error (or deprecation notice) as soon as AbstractBaseClass is compiled, rather than waiting for something in the code base to call "new ValidSubClass". Similarly, if there's a long constructor with a return statement inside some rarely used conditional logic, I would prefer to be told immediately that there is a mistake, rather than having a production error when the rare situation happens. Once I'm told about the problem, I can choose between two things: 1) Stop the constructor returning a value, e.g. by replacing "return foo();" with "foo(); return;" 2) Rename the method to a non-reserved name, and if needed add a new constructor which calls the method and discards the result Thinking that through, having an error thrown only when calling with `new` would actually be *more* disruptive. I would probably vote "No" to that version of the proposal. Regards, -- Rowan Tommins [IMSoP]