Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94922 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 63677 invoked from network); 8 Aug 2016 12:47:24 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Aug 2016 12:47:24 -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:60102] helo=poczta.brzuchalski.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 47/8D-33134-A5F78A75 for ; Mon, 08 Aug 2016 08:47:23 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by poczta.brzuchalski.com (Postfix) with ESMTP id BF8AF298423F for ; Mon, 8 Aug 2016 14:47:18 +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 lcio_86PZ43S for ; Mon, 8 Aug 2016 14:47:15 +0200 (CEST) Received: from mail-qk0-f180.google.com (unknown [209.85.220.180]) by poczta.brzuchalski.com (Postfix) with ESMTPSA id BA703298423A for ; Mon, 8 Aug 2016 14:47:14 +0200 (CEST) Received: by mail-qk0-f180.google.com with SMTP id v123so187340922qkh.3 for ; Mon, 08 Aug 2016 05:47:14 -0700 (PDT) X-Gm-Message-State: AEkoousNnxuigdz0io05GhJDAavCBqMkLgiv6Ajc87k7N7V3pYkWTfxh14Gda1Fo4cDQp6DRXvnSyxHd12uM2w== X-Received: by 10.55.148.67 with SMTP id w64mr27399542qkd.78.1470660433918; Mon, 08 Aug 2016 05:47:13 -0700 (PDT) MIME-Version: 1.0 Received: by 10.237.53.155 with HTTP; Mon, 8 Aug 2016 05:47:13 -0700 (PDT) In-Reply-To: References: Date: Mon, 8 Aug 2016 14:47:13 +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=94eb2c084e84bfe6fd05398ed0f1 Subject: Re: [PHP-DEV] RFC - Immutable classes From: michal@brzuchalski.com (=?UTF-8?Q?Micha=C5=82_Brzuchalski?=) --94eb2c084e84bfe6fd05398ed0f1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Sure my final properties was first thought, lately in discuccion it turns into immutable, sealed and final see here https://marc.info/?l=3Dphp-internals&m=3D146005058530881&w=3D2 Have you also read about Immutable modifier from last year? http://marc.info/?t=3D144766539400001&r=3D1&w=3D2 it's exactly about immuta= ble classes! 2016-08-08 14:46 GMT+02:00 Silvio Mariji=C4=87 : > Btw, I was not aware that there was already conversation on immutable > classes. > > 2016-08-08 14:31 GMT+02:00 Silvio Mariji=C4=87 = : > >> I see your standpoint, but I think it could cause confusion because of >> final classes. I think "immutable" is more suited here. >> What I try to achieve is something similar like case classes in Scala. >> >> Best regards, >> >> 2016-08-08 13:16 GMT+02:00 Micha=C5=82 Brzuchalski : >> >>> 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 >>>> would >>>> 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 th= is >>>> >>>> $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 >>>> immutable >>>> 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 clas= s >>>> or >>>> none. >>>> >>>> Thank you all in advance. >>>> >>>> -- >>>> Silvio Mariji=C4=87 >>>> Software Engineer >>>> 2e Systems >>>> >>> >>> >>> >>> -- >>> pozdrawiam >>> -- >>> Micha=C5=82 Brzuchalski >>> >> >> >> >> -- >> Silvio Mariji=C4=87 >> Software Engineer >> 2e Systems >> > > > > -- > Silvio Mariji=C4=87 > Software Engineer > 2e Systems > --=20 pozdrawiam -- Micha=C5=82 Brzuchalski --94eb2c084e84bfe6fd05398ed0f1--