Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108734 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 62664 invoked from network); 24 Feb 2020 10:01:54 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 24 Feb 2020 10:01:54 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 90162180088 for ; Mon, 24 Feb 2020 00:19:00 -0800 (PST) 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, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS 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-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (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 ; Mon, 24 Feb 2020 00:18:59 -0800 (PST) Received: by mail-wm1-f43.google.com with SMTP id t14so8308717wmi.5 for ; Mon, 24 Feb 2020 00:18:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:user-agent:in-reply-to:references:mime-version :content-transfer-encoding:subject:to:from:message-id; bh=7YYdDuIXt1Trben4aEaFqMXDPgXI9cxZmxItPwYv43k=; b=amCCGy2lAIWvvPWPgmQdd3vrPiGrLSHI1OeS6dLtu0iyxCW42WvHX7xy94an5TLJRw 3gMAfY/E1MgObA+/VJ3euKojiedTv3I+qmsOGVEezWhs9QyC78puB87O21+uE7f49HiM sziC8qsHSLN0/V+kPmiljiE+HPs7nh6lFIhYfv3O4h9CD3FEusGxkMgAmfgD22usQnzq jOynzOCZJi+u3+7kaLGLYvC+ohIltyNG6hP2ySUodJ2fRJ9GA9p7xY2mSHhDL6fuYUUi 31N0uZFVEuBvK0zhXLbSvZor1nv9lWOcsY7RYl7i8EwiH0ddqBYzc1HUjScJJAL8iIDl x0tQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:user-agent:in-reply-to:references :mime-version:content-transfer-encoding:subject:to:from:message-id; bh=7YYdDuIXt1Trben4aEaFqMXDPgXI9cxZmxItPwYv43k=; b=P5vBPC/3bicGlRnBCf53kNG5H4HaGgHP/pLs1O2u8RTB6FpWZsOZFBANKTeEPfPGkZ 1t4xmXTCnD3m8W28HpAJLoFr5QJe4tAjDmiFQpCe18sSX1jJaUoPcG2UJDt5dvwTX80U i7kt5HpxYQEQ1AZhss/3r0IlDrPBEJDVzZ6hd9Bdu6ggfnknIUIhJ+ScGBlDWL1yDKm4 +FI4RvijVBecAMfaVFvl3J9xycB8WOyKJ4BTrDLIV96azGPgrsgASCySaYYlHXl7a0U7 D+F962Vb6xN4g7Re3tJb+38XrWtvM806Fa7aAhJvlfsyrqvq8uF4+9ipdNaTvB7V5cJ6 6LHA== X-Gm-Message-State: APjAAAXUDIu49wtEie8bGZ/GNRzVZt1U2l8YD2+EAw7eV/Y9oJtikotB 6bBVdsHGJAaeANHp/qATWANCsGTK X-Google-Smtp-Source: APXvYqwBxPuS4cRNypbUGUjoyZsRPuBbkH8r55KLwfM49tgetFdQAKklU1n7puq1IFYp9SUkpu+nVA== X-Received: by 2002:a1c:6645:: with SMTP id a66mr21722446wmc.121.1582532338527; Mon, 24 Feb 2020 00:18:58 -0800 (PST) Received: from [192.168.0.12] (cpc84253-brig22-2-0-cust114.3-3.cable.virginm.net. [81.108.141.115]) by smtp.gmail.com with ESMTPSA id y185sm17978637wmg.2.2020.02.24.00.18.57 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 24 Feb 2020 00:18:57 -0800 (PST) Date: Mon, 24 Feb 2020 08:18:54 +0000 User-Agent: K-9 Mail for Android In-Reply-To: References: <8545d15e-ddd5-42be-8405-09697a077234@www.fastmail.com> <4d9688fe-cc57-44af-903e-05f4cbb1bbcc@www.fastmail.com> <452D962A-C588-4F04-B000-479EBEA9B9DB@newclarity.net> <9ebc648c-39d1-45b1-9f3d-9a799c6dec93@www.fastmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable To: internals@lists.php.net Message-ID: <135A46A4-9210-4FDF-AD48-460F3F7B14AC@gmail.com> Subject: Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties From: rowan.collins@gmail.com (Rowan Tommins) On 24 February 2020 03:26:19 GMT+00:00, Marco Pivetta wrote: >The solution is trivial: don't use cloning: > >final class Foo >{ > public function withBar($bar):self { > $instance =3D new self(); > $instance->foo =3D $foo; > // more assignments here - unavoidable > return $instance; > } >} This works fine on paper, but is completely impractical as the class grows= =2E Consider a class with 10 such properties, each with their own with* met= hod: switching from clone to explicit assignments means adding 90 lines of = code, all of it copy-and-pasted boilerplate that's hard to spot mistakes in= =2E It's also impossible to use with inheritance, or to compose with traits (a= s Diactoros does, for instance), because every with* method needs to know t= he full details of how to create a partial clone=2E Regards, --=20 Rowan Tommins [IMSoP]