Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122722 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 35F911A009C for ; Fri, 22 Mar 2024 08:17:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1711095492; bh=B7Tp9+4bZoy/1DJ7/p+LqnqSI/owGyB6t6/c0T68Vl0=; h=Date:Subject:To:References:From:In-Reply-To:From; b=lvMLWD7tcSUc0WctWjnmyxSZFf1LLbVw4S9+to9IvULaGvUZXRuCTBgjcT9urW7XE GATURhDGry7feTfULvmBHIyRd4tAgUm3uC1EeIUeyy6HSfvyVopDcNY18nBFu/aPwM 4m19yigAJMMN4V2Mf6VncQlUzDG7/SuP/5x1VdUL4AjyTxFnrD0tmk2g5hbKy7Qa7t 5mMdRTSxb2uThwti+8xZAJyxvHroyJglflK9jYrpPYv1+h41sejrqdcMyGXl8kQXAw fPm/BoZOLdoJby7gpTNMimPyiNjt3kDr2hKvr1EgBGrQgoxoKcW1YMF03vc371mvu/ kT0AaPdkyZR4Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DED95180341 for ; Fri, 22 Mar 2024 08:18: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.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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, 22 Mar 2024 08:18:11 +0000 (UTC) Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4147e135f4dso346015e9.2 for ; Fri, 22 Mar 2024 01:17:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seld.be; s=google; t=1711095468; x=1711700268; darn=lists.php.net; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to; bh=I1rFKYulqBK1n2sZwxD5OprNUG5hBbWe3EuPEfv/2E8=; b=Wgt+vFFpcV7rgzwlOFYaAIvJ81rzPalqkN61eIB7iqtyJHt6GIN7fRkcJCRaEKPsjF i64ZAzygjGQcLo4JHwsGZS4gWDpg5VeTx7n3/eqfg/fJM6bKQiaD+omFoNx6FGE4ppI6 EPFFQyA+H7dPrIXjc8VU06WsxYVmN1mCbaOv5Yrs4R5AdqVhDnOTmdnUZjMKYgIDtcSl XPV+Me9Z6ETFfvl0Zhpm5RZfveRVmRoEDt0o/QGVFLYYany0B0fksyd0Hc9OWYoIB1gC R+zOWzQ3s9N2dbzUXjxnAtEkvdhbDN3E7SgxrqA7XZa0WTdUpjRer8iUBKIeY6I0jyjf kJfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711095468; x=1711700268; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=I1rFKYulqBK1n2sZwxD5OprNUG5hBbWe3EuPEfv/2E8=; b=Bu4qBA4ayCEe2PukUUXwUIcNHOBBW95CxMfl5dMoaDNjtMBUzFU5iZbOgo22ExuB9V Rzlc/uofqFD4hmhB5EF5Um6ygKxN+ACDZZz04RmKv0lFNqeo5U2yBJMiiU5Dz6UVMx96 5OhLjtoCAfFDyRL5OZEJk/oSJrwH1c2RzHlDKXLLobjrZepozh2YRlPuX5dVC92jxp24 flTjNbQ1aTHwWpkF4jh1GotOS6B9joVeIf7Cy1otDWLs5aTbqm5005KNcMIfv4CDoHSA Q8V8lUcATR4pLRSnxw04AC7486EjvpFSRN/SKoAJJXySuSnuDfJrJjs/5FI/UXGHe2pu nTUw== X-Gm-Message-State: AOJu0YzCK6eO6eX1hUDdMVFW5DKsedlupu8KgDr8tmPAAwOzEKTxS1WM /wzvtC+wfhQkSEir09uoKOe6xBXipqs46chqo/C6RaidDvVrEX8s7hVxPV1VO5kDznb9SDH74rX I X-Google-Smtp-Source: AGHT+IEZfbsYMS9poxg8qtMS+MH5tYTqZneXn3vjNu1Zva2vnNTwADs5dqGZuxblBceLq6W3R7YDWw== X-Received: by 2002:a05:600c:68c9:b0:414:67ca:6aca with SMTP id jd9-20020a05600c68c900b0041467ca6acamr993568wmb.18.1711095468468; Fri, 22 Mar 2024 01:17:48 -0700 (PDT) Received: from ?IPV6:2a02:168:4b6e:0:355c:9b25:d:8295? ([2a02:168:4b6e:0:355c:9b25:d:8295]) by smtp.gmail.com with ESMTPSA id n11-20020a05600c3b8b00b00413eb5aa694sm2298690wms.38.2024.03.22.01.17.48 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 22 Mar 2024 01:17:48 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------wbjwVKEFeyqiVExyemEFJWMm" Message-ID: Date: Fri, 22 Mar 2024 09:17:47 +0100 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] Proposal: AS assertions Content-Language: fr To: internals@lists.php.net References: <3F78A125-1946-42E2-A4F5-A2B282BE2107@rwec.co.uk> <2d7ec203-6e80-445c-94f4-d29ef58743b1@rwec.co.uk> In-Reply-To: From: j.boggiano@seld.be (Jordi Boggiano) This is a multi-part message in MIME format. --------------wbjwVKEFeyqiVExyemEFJWMm Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 2024-03-21 16:02, Robert Landers wrote: > $a as int|float > > would be an int, float, or thrown exception. > > $a as int|float|null > > would be an int, float, or null. Just a suggestion here which might be more palatable to Rowan's wish for consistency (which I can totally relate to): We perhaps could make sure that as does not throw if used with `??`, or that `??` catches the type error and returns the right-hand expression instead: So to do a nullable typecast you would do:     $a as int|float ?? null To me this reads way more intuitive what will happen, and achieves the same in an also very concise way. The only catch I see is that it would also swallow errors about $a not being defined at all. Best, Jordi -- Jordi Boggiano @seldaek -https://seld.be --------------wbjwVKEFeyqiVExyemEFJWMm Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
On 2024-03-21 16:02, Robert Landers wrote:
$a as int|float

would be an int, float, or thrown exception.

$a as int|float|null

would be an int, float, or null.

Just a suggestion here which might be more palatable to Rowan's wish for consistency (which I can totally relate to):

We perhaps could make sure that as does not throw if used with `??`, or that `??` catches the type error and returns the right-hand expression instead:

So to do a nullable typecast you would do:

    $a as int|float ?? null

To me this reads way more intuitive what will happen, and achieves the same in an also very concise way.

The only catch I see is that it would also swallow errors about $a not being defined at all.

Best,
Jordi
-- 
Jordi Boggiano
@seldaek - https://seld.be
--------------wbjwVKEFeyqiVExyemEFJWMm--