Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129027 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 7A4551A00BC for ; Fri, 31 Oct 2025 13:20:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1761916824; bh=uZ3Q12d8nTKcLL3Uic6golN0/tqeJ7Mb4fDffq18iSk=; h=Date:From:To:CC:Subject:In-Reply-To:References:From; b=MiX75a1zLsMgso7Dg4/lbMVpOM7Un/o2UaVQbPgvh683ld/gKkFWaJ3U4Sf73xzTm +4Z+/z3GDCJZZ8R7YahZpPX0Jo0NI8FPsHgxV4TGEAMtISlDwfVinFBWoYuY+OkwQP QIHqtfB5MfGgCKA38pctSBdhuY5UDPyT9FBXI4UqEQ8B1e2rT5vXTPwsVAassK811z TMnfyP9dBI9+xvRVKEuYnHsPblIj+8ytwxW41Q1DBza5tsehzpLlJXDT0bUFyWssRC lFCpn3NrtkqPr8jPOmf4J0/vV79z5fhgvbb4Jcj6FzMw6NSw/PwR0l3WHDwMNDPYR2 gSal2HgcNMqjw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8149D180056 for ; Fri, 31 Oct 2025 13:20:22 +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-b8-smtp.messagingengine.com (fout-b8-smtp.messagingengine.com [202.12.124.151]) (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, 31 Oct 2025 13:20:22 +0000 (UTC) Received: from phl-compute-07.internal (phl-compute-07.internal [10.202.2.47]) by mailfout.stl.internal (Postfix) with ESMTP id 7EEF51D0018B; Fri, 31 Oct 2025 09:20:16 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-07.internal (MEProxy); Fri, 31 Oct 2025 09:20:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rwec.co.uk; h=cc :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=1761916816; x=1762003216; bh=r9OtzhmoN3G0VSPqa5pVgNxFuFVWwrpRZW2A7w0B4Qo=; b= YP6g0f4SYWXySxtCNWwu7yBgywII/ncVrPBsbFZMG3euhWT6hwdPZBit6NEMUay8 QtNvYdK+ecNyvcwBgzvHvKkeegO2WrkvLeUsPP0EPfQTh/NnVnw+5BRVhif+1bfy Mic/P1kNbsHl9eXEFCMq7YS6XJaSGi/iOWHASJ+SiPMbuGuyQ9cAH/Z4fVmYO/r0 3CTS4OniPWAUuu9ojWeatlW0LgLpzemzyEo9pFLuzDhKnPf/Apxniyy7X1FGJvJ9 dXqEqkmm1yw1LUYOVCQEnHdFfoOyh1Cz/d2xeLuGyQy1S+FUzfv1a5sIr1VyEUGR hN5gETioVQbfDecY6d7cwg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=1761916816; x= 1762003216; bh=r9OtzhmoN3G0VSPqa5pVgNxFuFVWwrpRZW2A7w0B4Qo=; b=S pDZ0xeFi+nPpPA/1B4Q5sEqCHal7pEf7ON5nRreLyB/C8fZo6ztUDZd3g62xiZ37 HxFheVHQRQC9OhaEotf8a9QwhlLWKfoYHQSSGOMq4z0ZMJS5Zjp8UKQ5C3ufocZu faPWokEsbB/lvJ0xXoKJHxyXzPJTExFonFXS7KVTm9cCNJS2/0bZccNSOcqHU0OQ KiSsGTaBcjN52RG1vD0kdPGlTHwNfTTfs+cpSq55Q4mm38MKfOsJiLX3jZ76lJcN o8ATV0xHfZRxQ7TYlMZtb5vrB5WqpUewGaAHMH1GBHfiolMsnn4pOTCWQo9suU6i 9dEJ1Kt7FH+6g2pMJAz9w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggdduieelheelucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucgoufhushhpvggtthffohhmrghinhculdegledmnecujf gurhepfffhvfevufgfjghfkfggtgfgsehtqhhmtddtreejnecuhfhrohhmpedftfhofigr nhcuvfhomhhmihhnshculgfkoffuohfrngdfuceoihhmshhophdrphhhphesrhifvggtrd gtohdruhhkqeenucggtffrrghtthgvrhhnpeeijeehgeekvdeffeeigfeljeevleegfffh hedtgeegjeeihefhuedutdejleejueenucffohhmrghinhepfehvgehlrdhorhhgnecuve hluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepihhmshhophdr phhhphesrhifvggtrdgtohdruhhkpdhnsggprhgtphhtthhopedvpdhmohguvgepshhmth hpohhuthdprhgtphhtthhopehinhhtvghrnhgrlhhssehlihhsthhsrdhphhhprdhnvght pdhrtghpthhtohephhifrghpgidruggvvhesghhmrghilhdrtghomh X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 31 Oct 2025 09:20:15 -0400 (EDT) Date: Fri, 31 Oct 2025 13:19:12 +0000 To: internals@lists.php.net CC: HwapX Subject: Re: [PHP-DEV] [RFC] Nullable and non-nullable cast operators User-Agent: K-9 Mail for Android In-Reply-To: <0dd89bc1461d0b75c7bae60212466e77@bastelstu.be> References: <0dd89bc1461d0b75c7bae60212466e77@bastelstu.be> Message-ID: <2904F104-76D8-4DB9-8426-50FCAB0D0C78@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 31 October 2025 12:04:29 GMT, "Tim D=C3=BCsterhus" = wrote: >Given that the proposed semantics matches that of function calls, I share= Rowan's suggestion of using =E2=80=9Cfunction-call style=E2=80=9D casts: > > function string_internal(string $input): string { return $input; } > function string(mixed $input, bool $passNull =3D false): string { > if ($passNull && $input =3D=3D=3D null) return null; > > return string_internal($input); > } > > $input =3D 123; > $str =3D string($input); > var_dump($str); > >In fact this is already valid PHP as of now and would allow polyfilling t= he new operators: https://3v4l=2Eorg/ldvFb and it nicely circumsteps all th= e backwards compatibility and ecosystem impact as well as the precedence is= sue=2E The only issue I'm seeing is possible confusion with the existing `s= trval()` and friends=2E But perhaps this is not relevant in practice=2E The ability to polyfill is very tempting, but I think this would be a dead= end=2E There's no natural way to express nullable types, and no way at all= to allow arbitrary union types=2E It would be like having "string_function= foo() {}" instead of "function foo(): string {}" That's why both of my example syntaxes had the type as some sort of *param= eter*=2E I don't think there's any way around introducing new syntax for th= at, because you can't "pass a type" to a normal function=2E There's also no obvious reason why int($foo) and intval($foo) should do di= fferent things, and neither is inherently "better"=2E The new int() would cover the "assertion" case (where an invalid value is = a surprise that should abort processing), and (int) or intval() would cover= the "sanitisation" case (where you want to substitute an empty or chosen v= alue for invalid input), but the names don't tell you which is which=2E And neither is useful for the "validation" case (where you want to efficie= ntly test user input)=2E Rowan Tommins [IMSoP]