Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129097 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 55CF61A00BC for ; Wed, 5 Nov 2025 22:48:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1762382898; bh=U0KTWFfFFHsX5TCjZ19jKhteoKCIgLj6JtB9sBAtiSc=; h=Date:Subject:To:References:From:In-Reply-To:From; b=k8Ir9/uXiRWCeIEFzQs1xWgUgz5i1n4WFkBovUFYU3LW8vE6A4cudmQw7qSYCCFiI EXytCbeZ71UCc+WwiIuhvrAnXx5qhIhllAnqqPWUZB/sRpO/IzHm7HkbKSvNEGtjax j/Vt8L+GAJV3RJPVcSkT/sS8qkUZm1dvsEPTNm3jGXOEb4M0Pu/DWSfrGlB+KNh1BB 6/pqbnabnw4YK3TP1MuEt9Wbmd33Zlwqj2wikyhVibCcU+IgeYjkT9BEAzNcOicFpb JZIQzj0TUhVuHZKazqQ93f7LQVMjwtC3JQa1WnNrK5EyWKrO8/v+2otxT6yfYUzPe4 nGgcPPywPLvlA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 20F441804B9 for ; Wed, 5 Nov 2025 22:48:17 +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=-2.8 required=5.0 tests=BAYES_00,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-b7-smtp.messagingengine.com (fout-b7-smtp.messagingengine.com [202.12.124.150]) (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 ; Wed, 5 Nov 2025 22:48:14 +0000 (UTC) Received: from phl-compute-09.internal (phl-compute-09.internal [10.202.2.49]) by mailfout.stl.internal (Postfix) with ESMTP id A155D1D001BD for ; Wed, 5 Nov 2025 17:48:08 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-09.internal (MEProxy); Wed, 05 Nov 2025 17:48:08 -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=1762382888; x=1762469288; bh=6SPSIajzzCOOE8LGuM35gjV5s55gE9z2RuJPmnRorcs=; b= Nnu+czKu7Wyi5naS3b0RI9J1wCcSSfKR5+lzUl+dp/sUnu1rLGyHKn/PSPx6oSPI 8JGDhsu6Hk/lFeeTE4KL+TrJS3NZgIJ2K2UWrrqDd45Vt9P7rp/ZwEPvEBt/et7/ 2wH4EtBVt8xQoXlK5GmRjrGr/9MPgTPJ/5a5LOwjj/4OKwrhTukMa/InPYkZY12g 6eBNQ+7InnAkCQxtht17jx0xJOfvs82KG2pEJ/lJbBYDQ7Wd/D2PBZm+zFyKWozD Nm4YbkXQ6ZtAotFb31MjgZ3mJvvJkvRm/7n7uF7AaqwmysQq4y1yqDRcCw4CJQSN 6ERTaKik2xCB+s8mRuZcOw== 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=1762382888; x=1762469288; bh=6 SPSIajzzCOOE8LGuM35gjV5s55gE9z2RuJPmnRorcs=; b=cWr73ND1RPs9HkZUW ZTz9jXMTBmGufnESDnUdnFWPy/iTtxleBxiBJ8E1gGcK6Oyl/i02MXs9Ls/bWxj5 mcTUjEw7feTMpyKHok0RQRAvis8HrmnhF+VUtA7etzcZrFLkf9ygosQYhdu5hAPu NNbSO5xzBxnYBX5hLFK4aEGkAbdJNUAzn9BiTBHBBiwCZHEKxzAPXrEQrY0txxWX HqtW7W7VYlzjCaszK9GC42ZahJXZPaVEdBjjjv/0WWSktlmEhMV6ASFSHFLmAgVa I4KGRtT5b7Y63VufPDj6xnveS4K4YzXuQ9JFqn3EYvq8zXPn2/J7/mYNRfJMPXNR pKUww== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggddukeehudegucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucenucfjughrpefkffggfgfuvfhfhfgjtgfgsehtkeertd dtvdejnecuhfhrohhmpedftfhofigrnhcuvfhomhhmihhnshculgfkoffuohfrngdfuceo ihhmshhophdrphhhphesrhifvggtrdgtohdruhhkqeenucggtffrrghtthgvrhhnpeffke evudffuddvheejvdefkeelfedtudegfeehjeduheegieduffeggeegveefheenucevlhhu shhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehimhhsohhprdhphh hpsehrfigvtgdrtghordhukhdpnhgspghrtghpthhtohepuddpmhhouggvpehsmhhtphho uhhtpdhrtghpthhtohepihhnthgvrhhnrghlsheslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 5 Nov 2025 17:48:07 -0500 (EST) Message-ID: <2529fb76-6b6c-4304-98b9-1ffa034e1e1f@rwec.co.uk> Date: Wed, 5 Nov 2025 22:48:06 +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] [RFC] Nullable and non-nullable cast operators Content-Language: en-GB To: internals@lists.php.net References: <9BE876E9-93BE-44C5-9C12-8E2C6FF0766F@rwec.co.uk> 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 05/11/2025 08:38, Alexandre Daubois wrote: > What we propose is to align these new operators to already existing > rules applied to function arguments. This is, indeed, stricter than > current cast operators. But I wouldn't say it has*nothing to do* with > the title of the RFC. > Maybe it's not perfectly accurate. If the naming is a problem and > should be changed, I'd be happy to hear suggestions and update > accordingly with a better name. Let's imagine how someone would describe these two expressions if this RFC passed: (int)$foo (!int)$foo Here are the differences I see: 1) The first casts any non-numeric input to zero; the second throws TypeError. 2) Certain values, such as "123foo" are considered numeric by one, but not by the other. That's it. There's no need to mention null specifically, it's just one of many non-numeric values. In fact, people might forget to mention point 2, because the difference between "always returns an integer" and "may cause your entire program to exit if fed unvalidated input" is far more important. So, if you want a name, I suggest something to do with "throw" or "error". But the problem I see with the RFC is deeper than that: there's no actual discussion of *why* throwing a TypeError is better, or *when* this completely new form of cast would be used. As I've tried to argue in previous messages, exception-handling is *not* convenient for tasks like handling user input. It is maybe useful for deeper code, where you expect the value to already be validated. So I think we should be looking at more than one type of new cast; or at least a choice of syntax that anticipates that. As for the other part of the RFC, looking at these two expressions: (int)$foo (?int)$foo I would expect the *only* differences to be to do with null input, and maybe null output. But in the proposal, using the new operator will *crash my application* for values where the other returned zero, and even for values where the other returned non-zero integers. If that part of the proposal goes to a vote as currently written, I will vote No. -- Rowan Tommins [IMSoP]