Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:95875 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 86179 invoked from network); 9 Sep 2016 20:01:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Sep 2016 20:01:26 -0000 Authentication-Results: pb1.pair.com header.from=marijic.silvio@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=marijic.silvio@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.218.41 as permitted sender) X-PHP-List-Original-Sender: marijic.silvio@gmail.com X-Host-Fingerprint: 209.85.218.41 mail-oi0-f41.google.com Received: from [209.85.218.41] ([209.85.218.41:36215] helo=mail-oi0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 94/C6-46544-31513D75 for ; Fri, 09 Sep 2016 16:01:24 -0400 Received: by mail-oi0-f41.google.com with SMTP id q188so47402772oia.3 for ; Fri, 09 Sep 2016 13:01:23 -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=/1Slc/W1L2hZl3L3lrbpBdzh0tvganVO6/lo9W3d3OM=; b=FLUMzeh/zV4OPrmsXoER1q9cxKVcTML2vAX6sFlYJARjbXzbPegjHLd3Rrhh4Mbac9 iQ+/KoxHz0n3sT3tlAiXkhpbNiNQtVZKurx6zQm3E/v7+DqpqzbGp1ru7mKxJh5XJQJy kHNAHRwQFQ1zBPGinfMcX7LUFSvSW4nlwYLcDWn1e8klYCnFZU0HeOs4Qp8fEYVBF22l /ue1rzW5oiYaQvnK5HDne0uymqAdBtB3Ulb5JsgGdeBSi0+wCx82um1PilEnTcudsH91 rE8f2ovHa/3cGHrSCTnKLr4CxQZ4mhkHlIXtkT5osSEq01S+1Sqx/HJeaQLG+m9H9L0U bF4g== 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=/1Slc/W1L2hZl3L3lrbpBdzh0tvganVO6/lo9W3d3OM=; b=TUY+9LisqPLUUNp8+0th+rFsTL/NOj8jGG0pD85AxysJZTGme9sXwIQBy9GOL9bk+O RF2X1MkGF6BTHE8/XFGJAtdVsm4oLKpIR0pmxmKqo3fBb7QWmfq7CuJhvb1E79eFuCRD iazUqgH2vAus+atZsfH34fopbq5fyuQRTT8i5pfAydohajuBhCjWc5nYDtqSpM8xFtat 5b3476SWvZ+g34hJUT3FO0+uZLcJpgqGc2TkUiXtXLucSqsXQ8IHzWugC6GuXsOthUta I5MXgilAlRpd9nm0JpAcQZIbhSOolqrkCRsBug89szNymx9KCaBM/YomAFIQ+9S+nz36 Uc8g== X-Gm-Message-State: AE9vXwNQ/LaNYVykJ8yNRNWlkmJ7p8AkSW503Faa9sLvFMIe1yZooPfUrKxRKBPcK9gD2P2gnlPxgbZ/OgzXKw== X-Received: by 10.202.245.215 with SMTP id t206mr8257414oih.87.1473451279734; Fri, 09 Sep 2016 13:01:19 -0700 (PDT) MIME-Version: 1.0 Received: by 10.36.207.134 with HTTP; Fri, 9 Sep 2016 13:01:18 -0700 (PDT) In-Reply-To: References: Date: Fri, 9 Sep 2016 22:01:18 +0200 Message-ID: To: Fred Emmott Cc: PHP Internals List Content-Type: multipart/alternative; boundary=001a113b093a1f6298053c189c7f Subject: Re: [PHP-DEV] RFC - Immutable classes From: marijic.silvio@gmail.com (=?UTF-8?Q?Silvio_Mariji=C4=87?=) --001a113b093a1f6298053c189c7f Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable @Fred Thanks for taking interest. I still need to fully patch reflection extension for this. We had more important discussions in the past two weeks= . Cheers, Silvio 2016-09-09 21:46 GMT+02:00 Fred Emmott : > I see Reflection is still todo; should there be a similar escape hatch t= o > ReflectionMethod::setAccessible()? > > This would allow things like: https://gist.github.com/fredemmott/ > 01ad55c0c03c8d7ba62bbd6e9fb23686 (apologies for the hack-like syntax) - > the =E2=80=98every property must be a constructor parameter=E2=80=99 appr= oach in the RFC > seems like it would rapidly become unwieldy for classes with a large numb= er > of properties. > > Regards, > - Fred > > > On Aug 8, 2016, at 3:31 AM, Silvio Mariji=C4=87 > wrote: > > > 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 immutabl= e > 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 or > none. > > Thank you all in advance. > > -- > Silvio Mariji=C4=87 > Software Engineer > 2e Systems > > > --=20 Silvio Mariji=C4=87 Software Engineer 2e Systems --001a113b093a1f6298053c189c7f--