Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129022 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 36C731A00BC for ; Fri, 31 Oct 2025 12:04:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1761912276; bh=a0rAqUx0AAYV0xoENetqjMSlqydZ7Q1yFDRWxs43LxQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=dyzkdIQtAt7M0k7m12dup0q+OjOZEtyXKZOg8wzKP2ylDEAhuaPtWwxqrNAEqh+v4 KwPYVVLQbOK37dP0e+v4Jnrk/vcn6R3y/tMucgvfbBStc4oZNWEIfoAA4BPF6MtB6f myhsx+z187oHMjuzsuL3XmYU9A551zZ5DSDLtd+EXctZ+71hKZ3BVqLclAojzcxbnF pDupjoInL3IDaaNMHD5pY9yB2u/vrlZwu9Th4mQ/zCPsiYLeI+7Lc//cGBUfSGO5sc KRi42oztC8sU7AIsm9fUlRwoUeVg8t0c5o7cwUOMcLXQ1Z44begkw+ucMPbAj9oLAT X/f9M1RD0tQag== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id EDD2618002E for ; Fri, 31 Oct 2025 12:04:35 +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.2 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (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 12:04:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1761912269; bh=YJnyprTJNUjooVDuDszrSaduG/k6HlSWTd0yGI/Fd9w=; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References: Message-ID:Content-Type:from:to:cc:subject:message-id; b=IgM2ewOOq/tWliDGqzrRlJ2uxsAxVYaRrwBXlLnfnF1p+rjtIABphmD3TA6d8aTKF A2Xk//cPrmi/QxKGeyErVREcp65AqUeZslRyu87xDS2IvVYpCasIdbkC0Z7zMquuK9 A/mc1J2Mk9fLTh/xrNF1CwtXWbk4bdTmJGJLyniZYY7ae5WoMZuNoPc6LalpgQYZdQ YQ3bxQZ69H1bxfuxfwxXd2VHow3hFGUnmx3HQ0CjKUhO2gpPIuRX5XfWSM/quyJF3k DC+Wnw7J0XPlMwOZ9lD9W1qHrNBddbi+e+vVNFB8VlYK0cf1CB0TFJANwjz39BQpuz 0b7WAhvkP7oeQ== Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 Date: Fri, 31 Oct 2025 13:04:29 +0100 To: Alexandre Daubois Cc: HwapX , internals@lists.php.net Subject: Re: [PHP-DEV] [RFC] Nullable and non-nullable cast operators In-Reply-To: References: Message-ID: <0dd89bc1461d0b75c7bae60212466e77@bastelstu.be> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=C3=BCsterhus?=) Hi Thank you for the RFC. I agree that having functionality to do type conversions in a safer and/or more succinct way is useful. However Am 2025-10-31 10:05, schrieb Alexandre Daubois: > This is fortunately not a blocker to this RFC, as this would address > an orthogonal problem. As you said, we have plenty of time before 8.6! I share Rowan's concerns about the proposed syntax. And I disagree that that the proposed Future Scope is not a blocker for this RFC. If we decide to introduce new syntax for this type of casts, then the “Future Scope” might also be interested in new syntax. One big problem with the current syntax, that is hinted at in the backwards compatibility section is that PHP does not have a generic “type cast” syntax, but instead requires a separate token for each possible cast. This means: 1. It has quite a big impact on the ecosystem, since each tool working with the tokenizer needs to learn about the new tokens. Similarly, they also need to learn about new AST nodes to even make sense of the code. In fact the “RFC Impact” section from the suggested RFC template (https://wiki.php.net/rfc/template#rfc_impact) is completely missing from your RFC. Every RFC that introduces syntax has a significant impact on all kinds of tooling and also for users learning the language. 2. “no backward compatibility issues:” as an absolute statement is incorrect, as you acknowledge yourself right below: “The syntax (!type) is technically correct”. It is true that this is exceedingly unlikely to affect existing code, but it is wrong to say that there are no BC issues. The RFC template specifically states “Please include all breaking changes, no matter how minor they might appear.” With regard to reusing the type cast syntax, one issue I'm already having with the existing casts is that I don't have a good intuition about the precedence of the casting operators and the accepted PER-CS code style does not help there: $a = "1"; $b = "2"; $result = (int) $a . $b; // what is $result? Given that the proposed semantics matches that of function calls, I share Rowan's suggestion of using “function-call style” casts: function string_internal(string $input): string { return $input; } function string(mixed $input, bool $passNull = false): string { if ($passNull && $input === null) return null; return string_internal($input); } $input = 123; $str = string($input); var_dump($str); In fact this is already valid PHP as of now and would allow polyfilling the new operators: https://3v4l.org/ldvFb and it nicely circumsteps all the backwards compatibility and ecosystem impact as well as the precedence issue. The only issue I'm seeing is possible confusion with the existing `strval()` and friends. But perhaps this is not relevant in practice. Best regards Tim Düsterhus