Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118746 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 13323 invoked from network); 5 Oct 2022 06:28:23 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 5 Oct 2022 06:28:23 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2846C1804AA for ; Tue, 4 Oct 2022 23:28:23 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,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=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-yb1-f180.google.com (mail-yb1-f180.google.com [209.85.219.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 4 Oct 2022 23:28:22 -0700 (PDT) Received: by mail-yb1-f180.google.com with SMTP id e20so4770037ybh.2 for ; Tue, 04 Oct 2022 23:28:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=VmD4xfCqlVp6OqeP8soYGC/ozW0ubpMHueqOGsK6Vs4=; b=UNQ8Inn1SJ++fRRe/piUL92JMUuSVyPmBPaUN3tiuJiOhuBp7izA9MKI8aOpE/xWmj /4TYem09itxxwLsMfqv7ugsvPIXOKbLFGPmICcvl9ER6xL8sSbTuuPQDKsdBFkYDQQNA KsL60AvrjhzMCGLDP3xLkL7x7/vWpVd/wFqLVFVdCvRCo++fWGUppabLSSgNTmf09Dkk JLs+awrkHGM7uTE2gtDQd3AMm2o/mugMNX5MKbTr81x/Vdqu2O78Rl63nu6EORM5v4RG cDFdFX4CIVbgmE9xrfI/tMtpMeN+bV50ctMTuVxvbT1yDvSTLbl0AewwnXkM/HFg4ObI u6aQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=VmD4xfCqlVp6OqeP8soYGC/ozW0ubpMHueqOGsK6Vs4=; b=pY+HB+QvvB9+lQjQSfhztiUSbb+ZQHD5hc7dcReYdAWr27kgIA56SEH4TbQSlczJog k+iYODMLbawitT3o/79WAAAzZkfHwKDzhvy8x+QKO6Cn3FtIgICt9JpaHs4crDAboTGj XlE2Pb81ZUOVquCzDAyKqJ2VuHUj1fMS4qb08PZUupqY/RyXFlNIvoY6xUGFg1rcc195 XcSUeKqU4yrOpP83hpvBhDKIh2yz+aD4abn6F1LS4lvTui1BchvHn72sRBrDBwDPAV9f GVDrHKLjGfyK3x0YlGOsvzroLDo1uF0vnpsr1XCA36xx6+qZgfxvnbJCMmCuGjTtyv2j Gs3w== X-Gm-Message-State: ACrzQf1S4a7fqEqpBMc14VpKW/zqB4K1expuptOQ7U/G2x8FYWeaaplN AVXgoDHA0fFMCzlM/W3MaK+ykJgfD85oviukm/A= X-Google-Smtp-Source: AMsMyM5Q5d3UImAbXlBthv8D6q/i/f9jRA6G6XC1w2TPiyKMqUs8wE9epgF2rU1JTVpE0YZGbeZo4dyR5EEN48d3+Mw= X-Received: by 2002:a25:b805:0:b0:6bc:ff7:b3ee with SMTP id v5-20020a25b805000000b006bc0ff7b3eemr30744064ybj.616.1664951301928; Tue, 04 Oct 2022 23:28:21 -0700 (PDT) MIME-Version: 1.0 References: <6F41F6B1-E27B-4BF4-BDB0-66D63DA4F130@woofle.net> In-Reply-To: <6F41F6B1-E27B-4BF4-BDB0-66D63DA4F130@woofle.net> Date: Wed, 5 Oct 2022 09:28:11 +0300 Message-ID: To: Dusk Cc: PHP Internals Content-Type: multipart/alternative; boundary="000000000000eb7d0f05ea43ae50" Subject: Re: [PHP-DEV] Union type casts From: zsidelnik@gmail.com (Eugene Sidelnyk) --000000000000eb7d0f05ea43ae50 Content-Type: text/plain; charset="UTF-8" As I mentioned before, it would work the same alike way as if we called function with such type-hint. FMPOV, one of the most meaningful use-cases would be nullable casts (like casting `?string` into `?float` for example). Regards, Yevhen On Wed, Oct 5, 2022, 8:41 AM Dusk wrote: > On Oct 4, 2022, at 21:46, Eugene Sidelnyk wrote: > > $foo = (int|float)$bar; > > As written, I wouldn't know what to expect this to do with a string value > -- would it cast it to int or float? > > Based on the behavior of your second example, the answer appears to be > "float", so this syntax seems to be equivalent to: > > $foo = \is_int($bar) ? $bar : (float) $bar; > > Or, even more concisely: > > $foo = 0+$bar; > > I'd be even less sure what to expect when casting to other union types. > What would the expected result of casting a string to (bool|array|object) > be, for example? I'm not sure there are many meaningful operations which > could be constructed here. --000000000000eb7d0f05ea43ae50--