Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104743 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 4569 invoked from network); 15 Mar 2019 16:37:28 -0000 Received: from unknown (HELO mail-it1-f176.google.com) (209.85.166.176) by pb1.pair.com with SMTP; 15 Mar 2019 16:37:28 -0000 Received: by mail-it1-f176.google.com with SMTP id 188so10809923itb.0 for ; Fri, 15 Mar 2019 06:28:07 -0700 (PDT) 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; bh=jVtChxaO/Bcf3l0TPy4dSCMrzcLqWvX76KLeolRn73E=; b=L7hLX+jEx5ENgR1lLf1FUAtQUWYfHva/H2Swy5bbaHCVvPtQNNYJ4YE3G3kVWbTio3 L53o+zZWdLkVHGqWAABVLzDptFKdwwlNjL5a1vFJ1YfPg7LPgtLm8EPuztkbZDQFv4mQ oCXy9H8Wu4FGyU7OLCePTJcdptz8qN59KDlvxMnMriq1imkP8tdLKdkQnc3lpc/Tc0D3 swyHm9ZfvxcnuVsj0gbEY8hBqD81Kx4ck7g5WqU/qDtjBHVleQuT1ojMBZaZAWZ8xK1J daBSdQX/iwrJgOgyKgeRMUZVH2yBQL7l4amTeXQ7wga+fxPxbBeKpBLA4FR/l0xZPSoK YKIw== 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; bh=jVtChxaO/Bcf3l0TPy4dSCMrzcLqWvX76KLeolRn73E=; b=iwUOINb52H4riLcftFE2eDLWdDXo7/OHdPNLoqgSIUeewwvlN670rnX2wboohRyFiV 8sHpME1+dDsPZAo86bcmwKJebn8lbD0xN9ZUMtm0TTzg/4dh7pn4tmB4ibSHV6Zp6yga NrMIJgexNp1EMRByzJQE2LXJTzTc7MbVZ7F9iNGnlABeCAx03x58LSrSIF66zdNpeiT8 S3RTzJJUsZaAbrA5+x7mrSBFUpXIBzNuX7BPzvdTJExjp6BfkuYny67WzlVkZTUNHdbp 0MvQiS+V3XJDs+scU+ntN1e5CiSvNlJOvp9u2yR6plrUYzrYBZM7QNunES0lmYYUsgHe h0RA== X-Gm-Message-State: APjAAAUFsh3P01iLhDViaAPCiKIgs6NMHtRbxkIiUUWonH8Xzd8Prdn1 ioUon3vjXiFR8LQJ/Sb3HqCSA1SRgH6GAjjaAcXsKZyV X-Google-Smtp-Source: APXvYqzELNmXqNQ8KEf+TzD/eNoH7Wn5O6BaTxqY+yvTEhd+nSdVqeREDcSzzbyinGNMHKyKyE3OUE9DYlo83sNDrnQ= X-Received: by 2002:a24:164d:: with SMTP id a74mr1911377ita.84.1552656486543; Fri, 15 Mar 2019 06:28:06 -0700 (PDT) MIME-Version: 1.0 References: <5c8b20b5.1c69fb81.d9f23.2cacSMTPIN_ADDED_MISSING@mx.google.com> In-Reply-To: Date: Fri, 15 Mar 2019 13:27:55 +0000 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="00000000000056b8e705842202ca" Subject: Re: [PHP-DEV] [Proposal] Struct Data Types From: rowan.collins@gmail.com (Rowan Collins) --00000000000056b8e705842202ca Content-Type: text/plain; charset="UTF-8" On Fri, 15 Mar 2019 at 09:54, Nikita Popov wrote: > 2. Readonly properties: Without requiring an entire object to be immutable, > we can add support for readonly properties. This may be either a standalone > feature, or part of / based on a more general property accessors proposal. > This is reasonable, but only if true immutability is the aim, rather than pass-by-value / copy-on-write. True immutability is probably fine for small structs, like Point(x, y) or Money(currency, value), because any "modification" can just construct a new instance manually. But in some cases, it's more convenient to have the copying implicit, rather than needing a whole set of withFoo methods. Note that you could have COW structs with optional immutability, and get the best of both worlds: struct Foo { readonly int $one; int $two; } $foo = new Foo(1,2); $bar = $foo; // implicit copy-on-write clone $bar->two = 3; // sets the property on $bar, leaving $foo untouched $bar->one = 42; // error I'm not sure how to do this with only reference types plus readonly properties; you'd need some kind of "partial clone": class Foo { readonly int $one; readonly int $two; } $foo = new Foo(1,2); $bar = clone $foo { two => 3 }; // need to set the new property value while constructing, because it's readonly $bar->two = 3; // error $bar->one = 42; // error Regards, -- Rowan Collins [IMSoP] --00000000000056b8e705842202ca--