Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108735 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 64828 invoked from network); 24 Feb 2020 10:08:27 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 24 Feb 2020 10:08:27 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0C4521804E0 for ; Mon, 24 Feb 2020 00:25:35 -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,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,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-io1-f45.google.com (mail-io1-f45.google.com [209.85.166.45]) (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:25:34 -0800 (PST) Received: by mail-io1-f45.google.com with SMTP id d15so9385986iog.3 for ; Mon, 24 Feb 2020 00:25:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=KxIcosCYDyUkXtZcLhy1h32Zimw4h/91FL+a6Rs+7W8=; b=HNcjyMTLOT040jMosxx2+cE+KZ+arKrDfetcUli1n9TBe+TlJYeDsmYBiiWzAeAD7/ 8Oym6b82y0mKq8gWzoFSyu+Mb6mZNUv1I6x+O44S0iMRfx6sqbAJHUoLfE6BGqdQOx/U 8k1c3CtD6WLD5ssSdW8x8quUlEv1x6xFm3vG8/3MyJya4fhisOuP8fM/dOCwp4sEDAUh jja43pOooVWBcNwTagnTvLYt2GYq2ayhVIH832+h46T1p79i0aJDg9q8XsgCGXMPr61I i20Vn9ND7gE9SuNNktR5R0wL30t04KLW8Hay4ACr2hugGrKi/ENBoDJb4AKaZ2lhDknU IkNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=KxIcosCYDyUkXtZcLhy1h32Zimw4h/91FL+a6Rs+7W8=; b=Nh0XWp8hiuDTIPAfUdZKNLaS/AU/VkSX3ds9iIA/LZI88c4GJSgcKnJq6XkrsVJgWD WCdktwnI2SPvj8VoFdd9a58JgN3Q7w5bN8fFJGMu1L7hDr+dnjVrzKsf63ALqUoteQHz RNIIsdMks3wQJ/a+xahihbdyBagN9Usy75h6IgDTWooA+1os0RWcqpeNNKCuoGPBfvMM aZGTR39cu+6e6oDxWBtG5mXH3HFNXkmf21ZVciUwAbC5qBs2pyVXhxcA5dO6XD1SQ+DI yOcklUmgkXVhHwMVsXuji9SPDCnrsBhWLmlcAMnTHP4qPtvGc6jxXqHb6dI36OblwHY6 E2zA== X-Gm-Message-State: APjAAAXQI9Qo8hxeLJrceBnv5TIICJnw77qvXhK8aH6Dl8BiKBLQL8U+ v4UQmDkiZvFyQ4/RGgzXPQ6CGsi2rsFTGDJBTco= X-Google-Smtp-Source: APXvYqwufbWor1l5Q2xSRzl4rRLCYDM9Ln99p+y2NbZ2qhSggN0vv+zfwKsXkON1IbTRkmeovqNIzuvdL5AmAn6HNxM= X-Received: by 2002:a02:cc1b:: with SMTP id n27mr46298533jap.122.1582532732308; Mon, 24 Feb 2020 00:25:32 -0800 (PST) MIME-Version: 1.0 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> <135A46A4-9210-4FDF-AD48-460F3F7B14AC@gmail.com> In-Reply-To: <135A46A4-9210-4FDF-AD48-460F3F7B14AC@gmail.com> Date: Mon, 24 Feb 2020 09:25:18 +0100 Message-ID: To: Rowan Tommins Cc: PHP Internals List Content-Type: multipart/alternative; boundary="0000000000005ae77a059f4e1d4c" Subject: Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties From: ocramius@gmail.com (Marco Pivetta) --0000000000005ae77a059f4e1d4c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Feb 24, 2020, 09:19 Rowan Tommins wrote: > 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. Consider a class with 10 such properties Yes, considered it: it's fine. Also, the best approach would be to have a ctor with those 10 properties. It's also impossible to use with inheritance, or to compose with traits (as > Diactoros does, for instance) Inheritance would be ditched in favour of even more composition, but even then, inheritance is not a massive issue, especially when it comes to value types. Probably a couple hours of work to make a full PSR-7 implementation with the old tests running, and the new approach applied =F0=9F=91=8D For things that are more sensible, like a UUID, a Domain Event or a Command, this is really a game changer anyway. The good old Object Calisthenics rules do really apply. --0000000000005ae77a059f4e1d4c--