Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120078 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 86177 invoked from network); 20 Apr 2023 08:21:18 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 20 Apr 2023 08:21:18 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8D3981804AA for ; Thu, 20 Apr 2023 01:21:17 -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,NICE_REPLY_A, 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-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (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 ; Thu, 20 Apr 2023 01:21:17 -0700 (PDT) Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-3f17b967bfbso12748625e9.1 for ; Thu, 20 Apr 2023 01:21:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681978875; x=1684570875; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=SzoVCKqNwNKjdYE0lXQH47k4osgJu8mHc4CyUfQF1Qg=; b=a/gDGFV5i5u9ejfLqdkU5tfJGNZs5Tkli/MzwpKEs/SGTseZL8yPJtQLVI1+ZxsJ57 JifaFkOrjTnn4oqy5TsVPQRmomWmVjdhmKhzoLFnlBavR/LSKyafqopnbmZZS4zK+onJ nT79RPl/CzHA/TmEkhecyfqjjGFvy8GQo9KToMir2KSZM6U56tbOYI7AO17MiArKlqoF Tz75UEujvkgiG+CpjCviLWAvnuYcoC4Ad8MytUZlJOMCPFRPwZATlSdHldbaWPUD3inv 3sCA03ACTC/GhoQcI7wovwm8IAAk4Y7AYNMV6b2oC/FU2aHgd2eCEAscyh6ph3sU7MV9 H17g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681978875; x=1684570875; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SzoVCKqNwNKjdYE0lXQH47k4osgJu8mHc4CyUfQF1Qg=; b=ePvR1DUAIjig82To+Y9BzHf1cT/G+/dL/neJRxbBHc7yNDamnw5GE088qiRLtpvj4+ Er9ihqtYNEUmENwsIObjALsT2CidjQarczKmY+UXHNbMznvrwfNw6XWlUV50Q/3iNtkE JILXIXzho/mloOM4KvgOReaUX+37I0OxzvyQLjeSEy7WDdHxfJ8dq56PM0LguBMytR69 yS6hvAcG6FlOlW/80p1Ip7qmOn/oXa1R8pbZBNDr9kPzzjQ1gknlqcd6qGjmatecltTR yR6yjqZ9LcLxGWFbSm0AOkRj9W0R4tN6VHL0gQRAabMkISeNUD793es9FPxzVXBs9Mjm 1ZTA== X-Gm-Message-State: AAQBX9coSZPcB+20ak3VHQL7e2XoHkGTefJ6Vow/ltqYqsavJfDKjsep bJ6haJx0wLhlK+Nq5wI1s1amUhwuOQA= X-Google-Smtp-Source: AKy350YZfVKJlDBlqNc/ilxcAtXYMY12g2LviheHm7A8mVoytUeJBD7/QNHYSykNa3pgr8py+JyyMw== X-Received: by 2002:a05:6000:1181:b0:2fc:3596:7392 with SMTP id g1-20020a056000118100b002fc35967392mr574255wrx.24.1681978875350; Thu, 20 Apr 2023 01:21:15 -0700 (PDT) Received: from [192.168.0.22] (cpc83311-brig21-2-0-cust191.3-3.cable.virginm.net. [86.20.40.192]) by smtp.googlemail.com with ESMTPSA id r17-20020adff711000000b002f2b8cb5d9csm1312152wrp.28.2023.04.20.01.21.14 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 20 Apr 2023 01:21:14 -0700 (PDT) Message-ID: <8a4ba8bc-8749-3e4d-7711-8e8974576764@gmail.com> Date: Thu, 20 Apr 2023 09:21:12 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 To: php internals References: <687944e3-75ec-446b-bbd6-6d3d6856e864@app.fastmail.com> <1b842b25-c038-f647-67e1-b8c986b7d51d@bastelstu.be> <14DCA246-277A-44EC-B3A5-3809C5BCC7AA@gmail.com> Content-Language: en-GB In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] [Discussion] Clone with From: rowan.collins@gmail.com (Rowan Tommins) On 20/04/2023 08:11, Robert Landers wrote: > public function withStatus($code, $reasonPhrase = ''): Response > { > return clone $this { > $this->statusCode = $code; > $this->reasonPhrase = "Old: $this->reasonPhrase, New: $reasonPhrase"; > } > }; Note that this is not the current proposed syntax. Since the keys are not dynamic, the current proposal is this: public function withStatus($statusCode, $reasonPhrase = ''): Response { // perform validation here $reasonPhrase = "Old: $this->reasonPhrase, New: $reasonPhrase"; return clone $this with {statusCode: $statusCode, reasonPhrase: $reasonPhrase}; } > public function withStatus($statusCode, $reasonPhrase = ''): Response { > // perform validation here > $reasonPhrase = "Old: $this->reasonPhrase, New: $reasonPhrase"; > return clone $this with compact('statusCode', 'reasonPhrase'); > } The compact() function always feels like a relic of the same era as create_function() and call_user_func(), both of which now have dedicated syntax. That's what Nikita was talking about in the RFC section I quoted earlier: that compact('foo', 'bar') could be replaced with a dedicated syntax like [:$foo, :$bar] So if we insisted on arrays, that would be: public function withStatus($statusCode, $reasonPhrase = ''): Response { // perform validation here $reasonPhrase = "Old: $this->reasonPhrase, New: $reasonPhrase"; return clone $this with [:$statusCode, :$reasonPhrase]; } But I still don't see why an array should be the default case here, rather than using ... to unpack one if you really need to, like we do with arguments. public function withStatus($statusCode, $reasonPhrase = null): Response { $newProps = [:$statusCode]; if ( $reasonPhrase !== null ) { $newProps['reasonPhrase'] = "Old: $this->reasonPhrase, New: $reasonPhrase"; } return clone $this with (...$newProps); } Regards, -- Rowan Tommins [IMSoP]