Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115391 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 56476 invoked from network); 11 Jul 2021 22:56:36 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Jul 2021 22:56:36 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 178161804AA for ; Sun, 11 Jul 2021 16:19:42 -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.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 11 Jul 2021 16:19:41 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id F16395C0078 for ; Sun, 11 Jul 2021 19:19:40 -0400 (EDT) Received: from imap43 ([10.202.2.93]) by compute1.internal (MEProxy); Sun, 11 Jul 2021 19:19:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=esibiw jqMa9RgbpcMMGyTCmRk3/6SSKE+KWwtxiNing=; b=Kmn81ogQc6g1+wl7R0WstL HuRVygPW8ltZKb3sOxFQfHLRYYe63zc20FV7f8bcJY3uA7lxt4qCVrsGTWrkTTlR 8io80mikfR2nX12xD43fe86bb+VcsFJcjV9rf5C+xMkTw4O26MddJfWaRR3uo6HU pq4XAsI5Wi3VsGipfTYgM1mCrWUQp7Jk3MoKjAdmz4IJpHoPKqezbXigaTkfMuxC J/e96J28hKRn9T4ry8pk6+0AvP0qWzhSTFbzgX/vxtM9RsaaOG3lGC/qdCNfrNU6 6Hbn7diZayX5PNJ+AJDEFIwGwm+amavvA74SqNJ5ZeyO7CTqs+xsmN1ToIzjCV8g == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddruddugddvtdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvufgtsehttdertderredtnecuhfhrohhmpedfnfgrrhhr hicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh eqnecuggftrfgrthhtvghrnhepgeelgfekudeivddvteffueejffdthfejieevhefgffek udevkedtvdelvddvffefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 97CBDAC0073; Sun, 11 Jul 2021 19:19:40 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-531-g1160beca77-fm-20210705.001-g1160beca Mime-Version: 1.0 Message-ID: <0d28ee72-accd-4dfc-a8e0-018c99e4a86d@www.fastmail.com> In-Reply-To: References: Date: Sun, 11 Jul 2021 18:19:20 -0500 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] Type casting syntax From: larry@garfieldtech.com ("Larry Garfield") On Sun, Jul 11, 2021, at 5:30 PM, Levi Morrison via internals wrote: > I like Rust's From and TryFrom traits, which allow types to define > conversions into or from other types. The From trait always succeeds, > and TryFrom can fail. However, it's not a "cast" -- the user calls an > `into`/`try_into` or `from`/`try_from` methods. > > I would be supportive of defining official ways to convert types from > one to another, not necessarily casts, though. I think these qualities > are important: > > 1. Would have failable and non-failable variants. It's nice to know > that a particular conversion cannot or can fail. > 2. It should be amenable to static analysis. Tools should be able to > warn about missing paths for handling failable conversions, or that > conversion from A to B is possible but A to C is not. > > I'm not sure how to technically achieve this for PHP. I don't think > any casting proposal I've seen meets these characteristics, so I would > personally vote no on them. What are the use cases for integrated object to object (ie, class to class) conversion in PHP? Rust's type system is a very different beast, so its casting logic makes more sense there. I'm not entirely clear on what the use case is in PHP. When would that be superior to "just write an asFoo() method and move on with life"? Scalar conversion I can see, but every time someone suggests adding siblings to __toString(), there's major pushback. --Larry Garfield