Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:95902 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 73765 invoked from network); 10 Sep 2016 18:02:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Sep 2016 18:02:11 -0000 Authentication-Results: pb1.pair.com smtp.mail=ocramius@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ocramius@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.42 as permitted sender) X-PHP-List-Original-Sender: ocramius@gmail.com X-Host-Fingerprint: 74.125.82.42 mail-wm0-f42.google.com Received: from [74.125.82.42] ([74.125.82.42:37063] helo=mail-wm0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 72/F2-46544-1AA44D75 for ; Sat, 10 Sep 2016 14:02:10 -0400 Received: by mail-wm0-f42.google.com with SMTP id w12so82284188wmf.0 for ; Sat, 10 Sep 2016 11:02:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=9+RCe6bE2kIevE5S9M/lN7f9L1IteI682uxV9+HKlUI=; b=qnN7aT/aBi+GYrACNZ5/HoHQmgBwjjbaCPuGW8Jba56555y8YtW5JCEuN6IP539Mdt yP6Hjnqv2H7HPvRbQuaMti/1Fd2O5P6tfCta8ei+2Iaw/xqQnD6cz/H3wFn9sZ5XynBt vA4ivtbuV0MkcNoKsBQzU9FB7LBmf6f3FpvWBvr2qUEzOERqh6mdJOgK7Kr6eg2IMA2R YmKLEHmtPCAHuj4yVqDHObQDE2DkpeSgE5r3hxH8L9kR4BnyYAZHpNx4yHZ7V14FFavo IRbc6HDeLAgTKghbMQQgFMUp3WJ2gi7XieNLz961SJmmzVVbdq3qDsMCqETyRolH+FFO iRyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=9+RCe6bE2kIevE5S9M/lN7f9L1IteI682uxV9+HKlUI=; b=cDRbmDoiIGoosAgbHNDIEsxqdhaVpvmh1flCVVM2JOw82MdWL0qtWxWRsyygbuq9M7 63WyoOUrHJjsEVxZufIsm2c8MYlYG7xBv1CkTqgc8YUNT+aE2gVqRue74g8CbKKt80j3 T0aMDLEwrjs1qlNzTK97lcExP8+5w3L7pR0euDKBxrbRqZey4zoGRh353jw+D96QPpqR LZ18iqKBilQ21NZ8KdTFApwIwxJxnlv0PUjTKvj6YpqtQ6HpEfzQO1z+7KHs3ScotqLx +Ve8vyAcFu2z7hEKS81PS4qSw+AH5Yl3UITWnJECWaMaxa8gTZb8XJhaFWSoOkHbuUMV MeVg== X-Gm-Message-State: AE9vXwPpbS47CNroDFhq1xISY337omTxy3VWIZMYkrNy6XPhwyjX6C2ho+ompfH2ylTIkcG5azpezVia9a0XPg== X-Received: by 10.194.246.8 with SMTP id xs8mr7941612wjc.64.1473530525131; Sat, 10 Sep 2016 11:02:05 -0700 (PDT) MIME-Version: 1.0 Received: by 10.194.19.229 with HTTP; Sat, 10 Sep 2016 11:01:44 -0700 (PDT) In-Reply-To: References: <642a6e78-90ea-cbf0-ec1c-376c24e568c5@fleshgrinder.com> <0800a5ca-3d14-c541-1a1a-2574ec802b8c@fleshgrinder.com> <83fa661e-2d3d-6548-a506-fb969be31c0e@garfieldtech.com> <56acc1d9-f424-a460-59be-3a9a1a74b198@fleshgrinder.com> <95832b08-ee80-18c1-a3da-202eed51903e@fleshgrinder.com> Date: Sat, 10 Sep 2016 20:01:44 +0200 Message-ID: To: Niklas Keller Cc: =?UTF-8?Q?Silvio_Mariji=C4=87?= , PHP Internals List , Larry Garfield Content-Type: multipart/alternative; boundary=001a11c3ba88842b84053c2b0fe8 Subject: Re: [PHP-DEV] RFC - Immutable classes From: ocramius@gmail.com (Marco Pivetta) --001a11c3ba88842b84053c2b0fe8 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Sat, Sep 10, 2016 at 7:49 PM, Niklas Keller wrote: > 2016-09-10 19:41 GMT+02:00 Silvio Mariji=C4=87 = : > > > @Fleshgrinder, > > > > While I'm not sure at the moment about CoW, I can agree that we should > add > > immutable keyword as a interface modifier to make sure all classes > > implementing must be immutable. > > > As interfaces can't have member variables, that doesn't make sense to me. > It still makes sense from a consumer perspective, so having the restriction in the contract is quite good. If you accept a `Number`, you expect to be able to serialize/de-serialize it, and you expect it to be "locked", immutable. If you let an implementation of `Number` to have mutable state in, then you break all the code that relies on `Number`. Note that it is still possible to break this though, so maybe we'd need some other modifiers about behavior too (pure function modifier?) immutable interface Number { public function toFloat() : float; } immutable class RandomNumber implements Number { public function toFloat() : float { return (float) random_int(1, 100000); /* yo, look at my global mutable hidden state! */ } } Requiring immutable values in consumers will likely improve code quality/safety and reduce dangerous assumptions, and it will probably also allow for optimizations in the engine later on. Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ --001a11c3ba88842b84053c2b0fe8--