Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:95626 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 177 invoked from network); 5 Sep 2016 02:21:57 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Sep 2016 02:21:57 -0000 Authentication-Results: pb1.pair.com smtp.mail=michal@brzuchalski.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=michal@brzuchalski.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain brzuchalski.com designates 188.165.245.118 as permitted sender) X-PHP-List-Original-Sender: michal@brzuchalski.com X-Host-Fingerprint: 188.165.245.118 ns220893.ip-188-165-245.eu Received: from [188.165.245.118] ([188.165.245.118:43907] helo=poczta.brzuchalski.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 72/25-45301-3C6DCC75 for ; Sun, 04 Sep 2016 22:21:56 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by poczta.brzuchalski.com (Postfix) with ESMTP id 09D4A2984235 for ; Mon, 5 Sep 2016 04:21:52 +0200 (CEST) Received: from poczta.brzuchalski.com ([127.0.0.1]) by localhost (poczta.brzuchalski.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ImSzpJZKAMNt for ; Mon, 5 Sep 2016 04:21:48 +0200 (CEST) Received: from mail-qt0-f172.google.com (unknown [209.85.216.172]) by poczta.brzuchalski.com (Postfix) with ESMTPSA id 2FB242984233 for ; Mon, 5 Sep 2016 04:21:48 +0200 (CEST) Received: by mail-qt0-f172.google.com with SMTP id 93so86794556qtg.2 for ; Sun, 04 Sep 2016 19:21:48 -0700 (PDT) X-Gm-Message-State: AE9vXwP1ZBqC4Wdfll2fWUJmx35mzb9IT1O4TNe8wL0e/gs2050Pod8JEFtE9XQrguV608wDimXm47d3DZqtiw== X-Received: by 10.200.57.71 with SMTP id t7mr12055499qtb.80.1473042107371; Sun, 04 Sep 2016 19:21:47 -0700 (PDT) MIME-Version: 1.0 Received: by 10.200.56.100 with HTTP; Sun, 4 Sep 2016 19:21:46 -0700 (PDT) In-Reply-To: <642a6e78-90ea-cbf0-ec1c-376c24e568c5@fleshgrinder.com> References: <4f54308a-4a69-2e6b-2ed0-51d4336d1cd4@fleshgrinder.com> <5969d1af-48e5-1376-07fe-9568de538145@texthtml.net> <0e71d28e-1d64-5372-b58d-e54c7afae3b8@fleshgrinder.com> <642a6e78-90ea-cbf0-ec1c-376c24e568c5@fleshgrinder.com> Date: Mon, 5 Sep 2016 04:21:46 +0200 X-Gmail-Original-Message-ID: Message-ID: To: PHP Internals List Content-Type: multipart/alternative; boundary=001a113eddc28c9999053bb957fd Subject: Re: [PHP-DEV] RFC - Immutable classes From: michal@brzuchalski.com (=?UTF-8?Q?Micha=C5=82_Brzuchalski?=) --001a113eddc28c9999053bb957fd Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 2016-09-04 22:38 GMT+02:00 Fleshgrinder : > On 9/4/2016 2:29 PM, Micha=C5=82 Brzuchalski wrote: > >> Providing `mutator` | `mut` keyword as method modifier sounds liek a > good > >> idea, > >> althought passing `$clone` parameter as first additional param could > break > >> method declaration and would be misleading. > >> > >> Assuming mutator method is designed to return mutated clone of > immutable > >> object > >> having `$clone` variable could be handled internally without breaking > >> method declaration. > >> > >> Such variable could be unlocked while in mutator method and locked on > >> return. > >> I was thinking about additional check if such mutator returns `$clone` > but > >> not `$this` > >> but I don't see the need of it - assuming there is no what to change i= n > >> some > >> circumstances ther would be also possible to return `$this`. > >> > >> The return type declaration `self` could increase readability, but > should > >> not be required, > >> as some developers doesn't already use return types. > >> > > > > It could look like in this gist > > https://gist.github.com/brzuchal/e7b721e22a19cca42ec0d1f597a23baf > > > > This is exactly how I meant it, yes. I actually prefer it if the > variable just exist in the context instead of passing it as first > argument. It's less obvious that it exists but the same could be said > about $this. > > Would it be possible to have this thing just in time instead of > automatically created in every mutator function? > > public mutator function f() { > if (condition) { > $clone is created; > return $clone; > } > return $this; > } > > PS: I started overhauling the test cases and error messages and will > create a PR against your branch soon. I will start with the RFC > afterwards. Should I simply edit the RFC in the Wiki or should we manage > this somewhere else? > > You may begin with modifications on RFC eg. in a gist so we can all discuss about it before putting on RFC, is that okay to you? > -- > Richard "Fleshgrinder" Fussenegger > > --=20 regards / pozdrawiam, -- Micha=C5=82 Brzuchalski brzuchalski.com --001a113eddc28c9999053bb957fd--