Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118745 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 10231 invoked from network); 5 Oct 2022 05:41:54 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 5 Oct 2022 05:41:54 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D14711804AB for ; Tue, 4 Oct 2022 22:41:51 -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=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS63949 74.207.252.0/24 X-Spam-Virus: No X-Envelope-From: Received: from malamute.woofle.net (woofle.net [74.207.252.100]) (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 22:41:51 -0700 (PDT) Received: by malamute.woofle.net (Postfix) with ESMTPSA id 4F5D41F14E; Tue, 4 Oct 2022 22:41:49 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) In-Reply-To: Date: Tue, 4 Oct 2022 22:41:48 -0700 Cc: PHP Internals Content-Transfer-Encoding: quoted-printable Message-ID: <6F41F6B1-E27B-4BF4-BDB0-66D63DA4F130@woofle.net> References: To: Eugene Sidelnyk X-Mailer: Apple Mail (2.3696.120.41.1.1) Subject: Re: [PHP-DEV] Union type casts From: dusk@woofle.net (Dusk) On Oct 4, 2022, at 21:46, Eugene Sidelnyk wrote: > $foo =3D (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 =3D \is_int($bar) ? $bar : (float) $bar; Or, even more concisely: $foo =3D 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.=