Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120068 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 55774 invoked from network); 18 Apr 2023 16:48:05 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Apr 2023 16:48:05 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 282DB1804C6 for ; Tue, 18 Apr 2023 09:48:04 -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,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS24940 176.9.0.0/16 X-Spam-Virus: No X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 18 Apr 2023 09:48:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1681836481; bh=o3HQ2Jh5QpXQEAKWhMST8pFep6eHha/TOd0xU1jysSY=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type:from:to:cc:subject:message-id; b=DJKusx97jB6Dob40TwH2YoxVJkZaMHckXK2of+gCIAWCPJg6Iy87DNGzIegE1mnpv tG3ncZEcw2ov2Pub++GP2XCP3BYTARx5SxzsfQkzhIgMdOG/DGoxvrgK4+g03T0eUe L5n07TxnhsdFzCeQZre8rJMdCZUdkenjVhg/tqUcybTEV1HvUdTYPwj/aFZO2pqq3a iUttU6Y0z0sPgevJqQS1qxKf5QzJNp3eam5VSmO6Uf2mVLL+Mt/e3myzPHVAdHEDTA 8u7oP5xGa/0YmDbShH51dDIlyV6IxnOHGGQ8fGjR3sUE9KpKhVKA5H/gIunC/Jh8i7 oUaNKuRz2tHXA== Message-ID: <1b842b25-c038-f647-67e1-b8c986b7d51d@bastelstu.be> Date: Tue, 18 Apr 2023 18:48:00 +0200 MIME-Version: 1.0 Content-Language: en-US To: Larry Garfield , php internals References: <687944e3-75ec-446b-bbd6-6d3d6856e864@app.fastmail.com> In-Reply-To: <687944e3-75ec-446b-bbd6-6d3d6856e864@app.fastmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] [RFC] [Discussion] Clone with From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=c3=bcsterhus?=) Hi On 4/18/23 17:45, Larry Garfield wrote: > I agree with the discussion of Nicolas's alternative, which has its merits but also some possible limitations. My only major concern myself is the potential confusion between when to use : and when to use =>. Using the => version only for dynamic keys feels very clunky. In fact, I think the RFC is inconsistent on this front: > > $object = clone $object with {"foo" => 1}; // the property name is a literal > $object = clone $object with {strtolower("FO") . "o" => 1}; // the property name is an expression > $object = clone $object with {PROPERTY_NAME => 1}; // the property name is a named constant > > I would expect the first one to be a colon, not fat-arrow. Is that a typo? No, that is correct. Colon takes a bare identifier, fat-arrow takes an expression (that just happens to be a constant expression in that case). > Is there a technical reason why they can't just all use a colon? That would extend more nicely to supporting dynamic keys in the future for named arguments. I'd rather see only the fat-arrow being allowed. Unless I'm missing something, braces with colon is not used anywhere else, whereas braces + '=>' is known from match() and '=>' more generally is already used with array literals [1]. Having two similar syntaxes for the same thing is not great when both are commonly needed is not great. They need to be documented and learned by developers. Best regards Tim Düsterhus [1] In fact if the right hand side of with may be an expression that evaluates to an array, folks wouldn't need to learn new syntax at all: $newProperties = [ "foo" => "bar" ]; clone $object with $newProperties; and clone $object with [ "foo" => "bar" ];