Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94920 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 60307 invoked from network); 8 Aug 2016 12:31:20 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Aug 2016 12:31:20 -0000 Authentication-Results: pb1.pair.com smtp.mail=marijic.silvio@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=marijic.silvio@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.47 as permitted sender) X-PHP-List-Original-Sender: marijic.silvio@gmail.com X-Host-Fingerprint: 209.85.214.47 mail-it0-f47.google.com Received: from [209.85.214.47] ([209.85.214.47:38212] helo=mail-it0-f47.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 32/DC-33134-69B78A75 for ; Mon, 08 Aug 2016 08:31:19 -0400 Received: by mail-it0-f47.google.com with SMTP id j124so80654175ith.1 for ; Mon, 08 Aug 2016 05:31:18 -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=OAEMGEwUWWhWBvBlFlbhQFB/hf6dmiD+Fs1v/0qmxrg=; b=YlkLTjfdzg+XL95HxMEPfXtWgY8appef3xpxkMxfu+jwYV/w0WYHiKkiFbyfojIKHv 0rNGJxbg3h2Fuvd1MSj7sIBRFdoT1nvoxZ0AKi6p0qtGe8AOkF1M/nrCt+RLN7B8+JC9 /QtJn6LBX0JqKUQiXQIorwcdhqUQwldYz9i6NhLZOLXeLYqebFDsXgfYQytQooHrlkUx 6vLY0a7liL+0RwuoJayr6YygvWZqQ1Ybs1l3q/15Z0qKFzQ70sO6rqUHnCfxqZfYxsI/ BmbXQGr5z2V0zKiwSLzAy8XsTuJt5/qA/ckzk3mzhBrSnUJKGy2B/jN9RnDXScMrkhBN pbmw== 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=OAEMGEwUWWhWBvBlFlbhQFB/hf6dmiD+Fs1v/0qmxrg=; b=RkjxGSQEbkfdF6b57amF/5BUhMTuH4I/p67tVTodvot9IvJyioBv33/622AHt66FWg y11Y+W4l3oD8drRhWq6z4XWkd6M1CWLLNcT8qLN4mLWWAP1tQTohf1/FiL4cvhGPo45f 8Ihs+IHVx9FXucm1yUR6IlybCJEskqQOL19Hx1sIpkH0S2lWTaDQA0xZmUVHGnwU2EWM TGI3SlSrO1/BheE6LhjQ7XFbE4NDs+CGKvoXJmo3lTdz1KuiXoJti6w13lguL9DT7kIL tEaM37VJeMyZjMBmiTpU1vJb5sGBSrgu+poLBe5hrHsUcvDOvA8p4yLcFK5gplRF2Fb6 9CNg== X-Gm-Message-State: AEkoousyQfSiPjrdRWVwO5Zgmd7vG81QFqvgNkaovVRteCYL4gIzRwA/4gOxZXHRhicb+6PEyLEC7PXWHR4EZg== X-Received: by 10.36.152.5 with SMTP id n5mr16844195itd.79.1470659476391; Mon, 08 Aug 2016 05:31:16 -0700 (PDT) MIME-Version: 1.0 Received: by 10.36.215.198 with HTTP; Mon, 8 Aug 2016 05:31:15 -0700 (PDT) In-Reply-To: References: Date: Mon, 8 Aug 2016 14:31:15 +0200 Message-ID: To: =?UTF-8?Q?Micha=C5=82_Brzuchalski?= Cc: PHP Internals List Content-Type: multipart/alternative; boundary=94eb2c05f7f8ad0cd305398e972a Subject: Re: [PHP-DEV] RFC - Immutable classes From: marijic.silvio@gmail.com (=?UTF-8?Q?Silvio_Mariji=C4=87?=) --94eb2c05f7f8ad0cd305398e972a Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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 modifie= r > 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 this >> >> $email->email =3D "new@email.com"; >> >> >> Would result in error. >> >> I have already implementation up to certain degree, but I need one advic= e >> from more experienced developers. Where is the place where I could put >> logic to lock object after the constructor has finished? Maybe in zend v= m >> 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 instanc= e >> 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 >> > > > > -- > pozdrawiam > -- > Micha=C5=82 Brzuchalski > --=20 Silvio Mariji=C4=87 Software Engineer 2e Systems --94eb2c05f7f8ad0cd305398e972a--