Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:95874 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 84318 invoked from network); 9 Sep 2016 19:46:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Sep 2016 19:46:37 -0000 Authentication-Results: pb1.pair.com smtp.mail=fred@fredemmott.co.uk; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=fred@fredemmott.co.uk; sender-id=unknown Received-SPF: error (pb1.pair.com: domain fredemmott.co.uk from 209.85.220.51 cause and error) X-PHP-List-Original-Sender: fred@fredemmott.co.uk X-Host-Fingerprint: 209.85.220.51 mail-pa0-f51.google.com Received: from [209.85.220.51] ([209.85.220.51:35260] helo=mail-pa0-f51.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1D/66-46544-A9113D75 for ; Fri, 09 Sep 2016 15:46:35 -0400 Received: by mail-pa0-f51.google.com with SMTP id b2so31263710pat.2 for ; Fri, 09 Sep 2016 12:46:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fredemmott-co-uk.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc:message-id:references :to; bh=inFZiMIIM0TYZcxYr77Vb6v04kbsOgTY82kOHT/LxUg=; b=zP4NXhhTev1bvoU+Ax99YTjTNkkFgwrJwnm6k8Jpmt9ibhM+fJEtI07vX7OiNF30ys PLSnPwpGWqcdY8pmGxKKISL7EhUP24R1rF1R5HTsxu5vyg5p1NE/i6qY6VtHYaKB6GnS ma3vp3s8w4nKyR2ntUJV66Gxwvf7YGf2KP6yyhGUQhSnDkKmcFBUmwdvH5v3hnpYgTGx UZEi5o++i04jX9/VFzy/exAD5dcRkNnX2i38gwSCsrsRKd/y7arEl/TM0ZFh8ugoWlx/ cdWx9svvgzUxnlZuF/oACHknxaK/OHoUZmhLISClCrxEM+4iTn9ghuW+YbvV+JyKxkEZ V29A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :message-id:references:to; bh=inFZiMIIM0TYZcxYr77Vb6v04kbsOgTY82kOHT/LxUg=; b=JJrHv5n/JSbD1BHRttOwxytiCOO0IiMEq2cSlJUHXNWhm+lDMM/N9RUSOgjGAYDUUx kamefy8ed9O7GyN7lLe/JvXxE79qkPmpqmiQ8YxISA6bOklCc/U38jtrSy0Pf/ufFsm9 bWz4iZU2CTKKBMvjH5lvW5kVRDALSPfmnEQRUDkZR2+Zpuo5O+bVR2vaVY6ZGXuW/I/S Ulgqo43fepBXDPqLBKH3ahvzFyel9cxDiMu02ceSNhKmzJHmV8lLyVkOeTsFMg5lz5Ui dt0/HxTOU8+eKqSikXZHYSuXQogehLU5LtC2gRQ3uJjYOErSp/Fysbs7pZRvI/JAlm9Y CkkA== X-Gm-Message-State: AE9vXwPEV1JLL1rj4Vq3TUH8yawdtQ82/hcBjbH3HVyehNq0gOBoF4XsLM5Nyx+8BUuvHA== X-Received: by 10.66.171.197 with SMTP id aw5mr9633933pac.36.1473450390876; Fri, 09 Sep 2016 12:46:30 -0700 (PDT) Received: from [172.25.144.124] ([199.201.64.131]) by smtp.gmail.com with ESMTPSA id d9sm7171628pan.7.2016.09.09.12.46.29 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Sep 2016 12:46:29 -0700 (PDT) Content-Type: multipart/alternative; boundary="Apple-Mail=_DFA862C3-2D31-4238-A478-AFB18ADEDA5D" Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) In-Reply-To: Date: Fri, 9 Sep 2016 12:46:28 -0700 Cc: internals@lists.php.net Message-ID: References: To: =?utf-8?Q?Silvio_Mariji=C4=87?= X-Mailer: Apple Mail (2.3124) Subject: Re: [PHP-DEV] RFC - Immutable classes From: fred@fredemmott.co.uk (Fred Emmott) --Apple-Mail=_DFA862C3-2D31-4238-A478-AFB18ADEDA5D Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 I see Reflection is still todo; should there be a similar escape hatch = to 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 approach in the RFC seems like it = would rapidly become unwieldy for classes with a large number of = properties. Regards, - Fred =20 On Aug 8, 2016, at 3:31 AM, Silvio Mariji=C4=87 = wrote: >=20 > Hi, >=20 > 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: >=20 > =20 > immutable class Email { >> public $email; >> public function __construct($email){ >> $this->email =3D $email; >> } >> } >> $email =3D new Email("example@email.com"); >=20 >=20 >=20 > After instance of class is created, object is "frozen" so call like = this >=20 > $email->email =3D "new@email.com"; >=20 >=20 > Would result in error. >=20 > 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? >=20 > Some constraints are needed: >=20 > 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 class = or > none. >=20 > Thank you all in advance. >=20 > --=20 > Silvio Mariji=C4=87 > Software Engineer > 2e Systems --Apple-Mail=_DFA862C3-2D31-4238-A478-AFB18ADEDA5D--