Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94917 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 52758 invoked from network); 8 Aug 2016 11:16:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Aug 2016 11:16:36 -0000 Authentication-Results: pb1.pair.com header.from=michal@brzuchalski.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=michal@brzuchalski.com; spf=pass; 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:39637] helo=poczta.brzuchalski.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A9/8B-33134-31A68A75 for ; Mon, 08 Aug 2016 07:16:35 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by poczta.brzuchalski.com (Postfix) with ESMTP id D3C1D298423C for ; Mon, 8 Aug 2016 13:16:31 +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 YxJ5hdOBd0m9 for ; Mon, 8 Aug 2016 13:16:27 +0200 (CEST) Received: from mail-qk0-f177.google.com (unknown [209.85.220.177]) by poczta.brzuchalski.com (Postfix) with ESMTPSA id 466E42984239 for ; Mon, 8 Aug 2016 13:16:27 +0200 (CEST) Received: by mail-qk0-f177.google.com with SMTP id p186so192161659qkd.1 for ; Mon, 08 Aug 2016 04:16:27 -0700 (PDT) X-Gm-Message-State: AEkoouvZ8KHp8kzQCDkjOTdFEBbaORsOT2HTCtsdab5RLeWDCV/sEwDBNL4kbhw11iV0w7qJhD4OjJNWdNa2Rg== X-Received: by 10.55.71.197 with SMTP id u188mr26282609qka.97.1470654986554; Mon, 08 Aug 2016 04:16:26 -0700 (PDT) MIME-Version: 1.0 Received: by 10.237.53.155 with HTTP; Mon, 8 Aug 2016 04:16:26 -0700 (PDT) In-Reply-To: References: Date: Mon, 8 Aug 2016 13:16:26 +0200 X-Gmail-Original-Message-ID: Message-ID: To: =?UTF-8?Q?Silvio_Mariji=C4=87?= Cc: PHP Internals List Content-Type: multipart/alternative; boundary=001a114a902a0f972a05398d8cf9 Subject: Re: [PHP-DEV] RFC - Immutable classes From: michal@brzuchalski.com (=?UTF-8?Q?Micha=C5=82_Brzuchalski?=) --001a114a902a0f972a05398d8cf9 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi Silvio, Look into my talk about final properties https://marc.info/? t=3D145979255800003&r=3D1&w=3D2 maybe there would be something usefull. There is also talk about mutable and immutable properties and other class modifiers also about var and val. I'm not sure that it should be class midifier rather than proprty modifier keyword. regards, -- Micha=C5=82 Brzuchalski 2016-08-08 12:31 GMT+02:00 Silvio Mariji=C4=87 : > Hi, > > I would need your help with one idea. I'm working on one RFC that I'm wou= ld > like to submit. Idea is that after you initialize object eg. after > constructor returns, object would be locked, and you wouldn't be able to > change properties on that object anymore. It would like this: > > > immutable class Email { > > public $email; > > public function __construct($email){ > > $this->email =3D $email; > > } > > } > > $email =3D new Email("example@email.com"); > > > > After instance of class is created, object is "frozen" so call like this > > $email->email =3D "new@email.com"; > > > Would result in error. > > I have already implementation up to certain degree, but I need one advice > from more experienced developers. Where is the place where I could put > logic to lock object after the constructor has finished? Maybe in zend vm > on ZEND_NEW token? > > Some constraints are needed: > > 1. Child class that extends immutable class must be defined as immutab= le > also. > 2. If property on immutable class contains object, it must be instance > of immutable class. > 3. You can not have immutability per property, it either whole class o= r > none. > > Thank you all in advance. > > -- > Silvio Mariji=C4=87 > Software Engineer > 2e Systems > --=20 pozdrawiam -- Micha=C5=82 Brzuchalski --001a114a902a0f972a05398d8cf9--