Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123727 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 qa.php.net (Postfix) with ESMTPS id 4CB361A009C for ; Fri, 21 Jun 2024 12:47:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1718974094; bh=Oh836aCd0/QsGJMCuX5p6MUuFIivrcKCNvoen21AeMY=; h=Date:Subject:To:References:From:In-Reply-To:From; b=JT327EajnROL7JepAlC4jY0Y+ko5uVrHwrN8X4JyyTb6uioXD7EjMLiGXXCC1APa6 dDCPjNuncWa8ou/f7YtTsyhHw1MMsVoCCQp2HSWimtbFrrKPCMdlehYKMjBh6BPO7h YPvclFM7Cj41/zbyMFYwmiwsfEddHyIuv8uoBoxgtd8yk0BWrscWa46p61qudWCGR4 IV3ieHEOLUiJPPQJmdNFVRTdZld3kCuWeQ0Bd4szt1c39yvNWaaEI1fB6ZDOBTsrjp fa0uXgMbJYHS27mlNeNH16dje3fNx3kvGCo1VzjxgI/RmafU5g1DTdvGMaT6sDvPQ3 byzcpMRWroXVA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id F07501809E9 for ; Fri, 21 Jun 2024 12:48:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_40,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from smtp-190e.mail.infomaniak.ch (smtp-190e.mail.infomaniak.ch [185.125.25.14]) (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, 21 Jun 2024 12:48:10 +0000 (UTC) Received: from smtp-4-0000.mail.infomaniak.ch (smtp-4-0000.mail.infomaniak.ch [10.7.10.107]) by smtp-3-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4W5HDZ3WnJz4jJ for ; Fri, 21 Jun 2024 14:46:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=processus.org; s=20231208; t=1718974014; bh=NDhEQdGp0dm7t41oKxiYkTjjEiNlFHUqUiAjUJEwVAs=; h=Date:Subject:To:References:From:In-Reply-To:From; b=HiR6CgTUGrO0Lau8tmAr4mq+HeZQ7MVdU2WtG+/fJYA4o1/CHhfh8kkC9r67zvILr DUimC1W9j6EnmcNMnTZoqNnxnI7IYV3d8MK0cszc28vVnPkOryaKprhERYmdUyXLwt O+jv7dQLplaIoGIcoVa/qBNLEJO1jMyyUbES4wirwE8jZeYRcLp0XLYbVKKC6CTvkI k4HQVlOEznRNAz/O9NZXRX5aXCnxfiVSTCayAnSY4+5pJ5Y8BvGnkZbF5s8OCzRs9+ 5VktKHtF2raeBSnI7EqV31g2DYgWFYYae1YFRBTgrRNNe+Miy1yBZrm9Sn2vKr+g/0 C2rELph5wcP5g== Received: from unknown by smtp-4-0000.mail.infomaniak.ch (Postfix) with ESMTPA id 4W5HDZ053pznk6 for ; Fri, 21 Jun 2024 14:46:53 +0200 (CEST) Content-Type: multipart/alternative; boundary="------------69XBQYOWbjSy9dDdk2hq0h4S" Message-ID: <914cde73-3e53-44a8-94ff-bcf34000cc0c@processus.org> Date: Fri, 21 Jun 2024 14:46:53 +0200 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] Renaming "strict types" to "scalar type coercion" To: internals@lists.php.net References: <9d28c9tOCChpWUcP1SFiFwtf2-w2XAtDzHsmM73myA7zfBsn7TxxEqs-VCnxRAgZjsk2TxS55owmM8wSLgBQL8LgeQLntUQ9toeLMkjTVx4=@gpb.moe> <673a1803-83c4-44b4-bd73-4ba61e83412e@app.fastmail.com> <350c1531-9bcf-4e7c-824b-8d9904b9e48e@rwec.co.uk> Content-Language: fr-FR, en-US In-Reply-To: X-Infomaniak-Routing: alpha From: pierre-php@processus.org (Pierre) This is a multi-part message in MIME format. --------------69XBQYOWbjSy9dDdk2hq0h4S Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Le 21/06/2024 à 14:27, Robert Landers a écrit : > This is why I wanted to work on "as" part of the pattern matching. It > isn't clear what will happen with the actual pattern matching RFC > (yet), but being able to do: > > some_function_expecting_int($_GET['foo'] as ?int); And how about: some_function_expecting_int(\intval($_GET['foo'])); And moreover, I'd write something like this, but: function validate_int(mixed $value): int { if (null === $value || '' === $value) { return null; } if (\is_int($value)) { return $value; } if (\is_string($value) && \ctype_digit($value)) { return \intval($value); } throw new \InvalidArgumentException("What what!"); } some_function_expecting_int(validate_int($_GET['foo'] ?? null)); But the example might be erroneous, I see your point, nevertheless making coercion explicit doesn't seem really relevant to me, the one point I like in your syntax would be null handling. -- Pierre --------------69XBQYOWbjSy9dDdk2hq0h4S Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
Le 21/06/2024 à 14:27, Robert Landers a écrit :
This is why I wanted to work on "as" part of the pattern matching. It
isn't clear what will happen with the actual pattern matching RFC
(yet), but being able to do:

 some_function_expecting_int($_GET['foo'] as ?int);

And how about:

some_function_expecting_int(\intval($_GET['foo']));

And moreover, I'd write something like this, but:

function validate_int(mixed $value): int {
    if (null === $value || '' === $value) {
        return null;
    }
    if (\is_int($value)) {
        return $value;
    }
    if (\is_string($value) && \ctype_digit($value)) {
        return \intval($value);
    }
    throw new \InvalidArgumentException("What what!");
}

some_function_expecting_int(validate_int($_GET['foo'] ?? null));

But the example might be erroneous, I see your point, nevertheless making coercion explicit doesn't seem really relevant to me, the one point I like in your syntax would be null handling.

--

Pierre

--------------69XBQYOWbjSy9dDdk2hq0h4S--