Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128947 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 13B591A00BC for ; Fri, 24 Oct 2025 09:22:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1761297770; bh=AUXmhofT7FrpEhj9b3hmzHAU1zd/Sq89hDnM5LnGg+A=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=G5GdB1ipHuo6uO6HUSnq0B1f9I7ZaTEXajh/CVJOnPimB8r2D1dBUL7Q83Jl8cLQ7 OUZHJ6/suhF+ynDctCoMCLw7wpg7seHE3R7cm1CiPmoB4FhTwGsigmqQAOa1JSyPql v4X+koBwZUgtr6JgprXzS2S8CCAXKYIvQGrI/v0WJYUrxjnu16KoS+tYeOkDp2g7GD i6oNr6AZrMtoh8I1ZaZ6WKFl5u4pT0GPt7CSD+KP7rPclVlwYYRtlASzYtzTot75+H RVa8IEgB1IYlpfYzaNr3UhmK5CD3J/CM9ecjuKefQIfRSD1YZoog8/wiC/9jHTjtNm PfdulTIsoZJrQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9ED9E1801EE for ; Fri, 24 Oct 2025 09:22:48 +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=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, FREEMAIL_REPLY,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) (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, 24 Oct 2025 09:22:32 +0000 (UTC) Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-36bf096b092so18762651fa.1 for ; Fri, 24 Oct 2025 02:22:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761297746; x=1761902546; 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=/0CEcU63N10AR/3c6ovJei6iuom0AC+VAn5BzXTH0Wc=; b=nXZ4i/hgGjRX54vJnNkIVTcj77D6ZGN3gg9eeGzCt7I6+cz1YOnKs1xuqVwUsYUto/ or4mpuFJWC0wwQ/+X6USmEVLopSNRAx0Y+DA01twMnvZ6aLtU2zApBlr6o5IMtIu+DBC aFwb5PjedrEiVjFCow9lEVWHnTcH1Y9GL6I8zsRbyfN2DQo/z4q51Xhny6jJp7yO+Qc1 O6BtpWzTv616x9PF2U/ZOCF5/q54NI5D2bz1Z99jc1E9uUOwXobk05kehwvua6Gqizi5 3rUq/cW157J8rK8+1T5p0rDgOXvs1PjZ6fClOKF5f0+VGZq6R5Ux++BIB2l19WpGABqj 80Lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761297746; x=1761902546; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=/0CEcU63N10AR/3c6ovJei6iuom0AC+VAn5BzXTH0Wc=; b=biCM6C6eg8TpndafLebO3v8Q8dqkOR2Nm4rcXnvJFOkzGgYjfqdOty+QOufv5Jvz3J v2eJmAlebs3u66sp57C5u3idSicd+M0CaBZjHi+NgIrZiJJ+GCTtSYk6uwHBw8smHzlH m3HI0k0GKHUvq8LJApS4OZve3teCNMWGRWhA6gWxMlx9hfl9gN8oVXMMGyyF2NYyc88z qtbTTkJ/GrgwUuViDK9GD3jznoBmrZz3bTlHzIDJhDTROJKr396gFGcSSDlIudaw//zI IvJaD4oEevLnyijQljxS32j3pnfHYvJVhxPQqS2hoSQN5Riw6xkcXDkiDlB8tCGhKO7W GAeA== X-Gm-Message-State: AOJu0YzR8jzRI6iwPm5y+hiSc06+4WZHH8UCCgKCO9fS6zN23oFK/ib1 4qqfYRq14hJlSe3+jlcUD0ec4wyziaAdGdjitiyMNsVep/MT1Pt+v+eDG6z6RAlgCPnl5O81eGt KJZv4uPbxZeOu1sME/A09WHmlx+Z4/QtLPAkw X-Gm-Gg: ASbGncvC9pGcFB3cuU3LcGBKShgazDKfBCvMW3tKgsZPNF7OcsDJmkK8UYco2GF+ppE 0TbWgbPxNSSkmDhWQuTvwZ67CcZViSkAkdNsadH+pHKNoOe5ULyS3/BiZDU3xuJTH4F1RFsHUEZ 1Uu2eK5SHTQWlQ+XqpMeh4OzZrMyxqROAPFcP27QZ524VJTc+2vRWtzq7y8Ya1quHm5DJ6/8G84 EvwC596c9lT5rsmr1X2ciDFdzm95KBnsf3c6Vr9/A3XTSkunRMdPkrM4Wc= X-Google-Smtp-Source: AGHT+IHa+Pw3MUGiktBdEMbLq9LMp1SZN78v6afCt/E+eqtuBO94XizQ7m7oqCFBRbju4mSHki/OVNyL1gkzCLh81n4= X-Received: by 2002:a05:651c:b29:b0:378:dd6e:104f with SMTP id 38308e7fff4ca-378dd6e1adfmr15806911fa.27.1761297745165; Fri, 24 Oct 2025 02:22:25 -0700 (PDT) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 24 Oct 2025 11:21:58 +0200 X-Gm-Features: AWmQ_bl390O3_exEw-b5QIg0vIMNhNZJXAPNopuM5ON5TWpZ3GE2WWSHzpE7Yuw Message-ID: Subject: Re: [PHP-DEV] [RFC] Nullable and non-nullable cast operators To: Alexandre Daubois Cc: PHP internals list Content-Type: multipart/alternative; boundary="00000000000071c0450641e416e7" From: kjarli@gmail.com (Lynn) --00000000000071c0450641e416e7 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Oct 24, 2025 at 9:09=E2=80=AFAM Alexandre Daubois < alex.daubois+php@gmail.com> wrote: > Hi everyone, > > Nicolas Grekas and I would like to propose this new RFC to the > discussion. This proposes to introduce two new cast operators to the > language: `(?type)` and `(!type)`. > > Please find the details here: > https://wiki.php.net/rfc/nullable-not-nullable-cast-operator > > Thanks! > > =E2=80=94 Alexandre Daubois > This looks useful to me - In the RFC the "Behavior Comparison Table" the colors make it hard to read what's listed in the table, could this be adjusted? - We still end up having null coalescing operators (or isset) for arrays, would something like this work? ``` // suggested through RFC $quantity =3D ((?int) ($_POST['quantity'] ?? null)) ?? 0; // the underlying logic would be $quantity =3D $_POST['quantity'] ?? null; if ($quantity !=3D=3D null && ! is_valid_int_value($quantity)) { throw new TypeError(); } $quantity =3D (int) $quantity; // would be nice if it incorporated an "isset check" as it's effectively treated as a null value $quantity =3D ((?int) $_POST['quantity']) ?? 0; ``` --00000000000071c0450641e416e7 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Fri, Oct 24,= 2025 at 9:09=E2=80=AFAM Alexandre Daubois <alex.daubois+php@gmail.com> wrote:
Hi everyone,

Nicolas Grekas and I would like to propose this new RFC to the
discussion. This proposes to introduce two new cast operators to the
language: `(?type)` and `(!type)`.

Please find the details here:
https://wiki.php.net/rfc/nullable-not-nu= llable-cast-operator

Thanks!

=E2=80=94 Alexandre Daubois

This looks = useful to me
=C2=A0- In the RFC the "Behavior Comparison Tab= le" the colors make it hard to read what's listed in the table, co= uld this be adjusted?
=C2=A0- We still end up having null coalesc= ing operators (or isset) for arrays, would something like=C2=A0this work?
```
// suggested through RFC
$quantity =3D ((?int) ($_POST[&= #39;quantity'] ?? null)) ?? 0;

// the underlying logic wo= uld be
$quantity =3D $_POST['quantity'] ?? null;
if ($= quantity !=3D=3D null && ! is_valid_int_value($quantity)) {
=C2= =A0 =C2=A0 throw new TypeError();
}
$quantity =3D (int) $quant= ity;

// would be nice if it incorporated an "isset check" = as it's effectively treated as a null value
$quantity =3D ((?int) $_= POST['quantity']) ?? 0;
```
--00000000000071c0450641e416e7--