Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92094 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 41069 invoked from network); 5 Apr 2016 10:14:13 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Apr 2016 10:14:13 -0000 Authentication-Results: pb1.pair.com smtp.mail=ocramius@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ocramius@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.170 as permitted sender) X-PHP-List-Original-Sender: ocramius@gmail.com X-Host-Fingerprint: 209.85.217.170 mail-lb0-f170.google.com Received: from [209.85.217.170] ([209.85.217.170:36041] helo=mail-lb0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 81/92-27948-2FF83075 for ; Tue, 05 Apr 2016 06:14:11 -0400 Received: by mail-lb0-f170.google.com with SMTP id qe11so6086347lbc.3 for ; Tue, 05 Apr 2016 03:14:10 -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=RxDKX+xZ36HtXPCNxJuN1O7l9a/JlsYblCmi60FU6pY=; b=fEW5u3ND6VaEpKfDEaKCzBF3R5sJhfKvq6hjWmu1QSYvwBEl3Vc3TDRvxVFHDgpTkC eE/mNQiP353xcKMnj6KOKvpojOArxlFpnhE4JluLaAdfAj5pV0DWsgQoffAeVnVKlgTX 4MBni2UsKGvu2sfFy+hwG0DEJt1Ch9EVFxtzTlI4WgNgj4mw45IoLX9c2x4XS00c2cu+ VgmH+ijolgoh8a7w5gykEwrFT2hjfiCUBRPNDE7GLJNmLc0tqmX1OEXGEEkMqkJ7tfhm GsfHeXfpYriI7ZG1WtbvDkgN0RwjjorWj5klPSoqSKwqiELBpVorD59khxrBbvYDlccP C/5w== 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=RxDKX+xZ36HtXPCNxJuN1O7l9a/JlsYblCmi60FU6pY=; b=ThpI+d0SiB6MF9mLi69EUoeP/ngsOU8QV9nHnV7FxZgzf2lyQRBNy+8rYijedPVd7w Jfry5IiipGM2BErBZ3nwt0Gsh1uescu6D894jQ54DF9IVl1yUxpr+e/f+C+qOD5QIzK5 nYHhMGyGJCdllH2ybGvqEBgP8uXB2olxA8RwzmX+epTiESG/ofuXCSs8bo50PyOyUgKs +1llng5Cn4RPz3sJaTatZFst9vwZbCTs9M9wfgKYMgXyLCPu8Rs51BcRu6dgHqQMNe8l Yr1VnJxGiCdabmH5zKXZh/V4qy+b33csGj7Z1SrP/oFoLZp2C0G/TJDZ177fmm3DdfUx ++5g== X-Gm-Message-State: AD7BkJI5HaqfHINidjd5aNK2yrSaKWSAT10b+hOpoIoKZNRQixyYDK4tlRumafS/Qg3BaY4gG83oRv1hA+Gvag== X-Received: by 10.112.198.65 with SMTP id ja1mr3886739lbc.123.1459851247826; Tue, 05 Apr 2016 03:14:07 -0700 (PDT) MIME-Version: 1.0 Received: by 10.112.126.67 with HTTP; Tue, 5 Apr 2016 03:13:48 -0700 (PDT) In-Reply-To: References: Date: Tue, 5 Apr 2016 12:13:48 +0200 Message-ID: To: =?UTF-8?Q?Micha=C5=82_Brzuchalski?= Cc: PHP Internals List Content-Type: multipart/alternative; boundary=001a11c3409a0d406d052fba1be7 Subject: Re: [PHP-DEV] Final properties From: ocramius@gmail.com (Marco Pivetta) --001a11c3409a0d406d052fba1be7 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi, On 5 April 2016 at 12:06, Micha=C5=82 Brzuchalski = wrote: > Hi Marco, > > Ad. 1 it is posiible to redeclare in a sub-class final property as > non-final, here is some gist presenting my current impl working like: > https://gist.github.com/brzuchal/12ebda1efed59440a78ba43bff116728 > Does this work for public properties as well? > Ad. 2. `final` means class variable (like static) or class instance > property can not change their reference, it is impossible to replace zval > in such property, in my opinion `immutable` is object behavior when using > some methods you receive newly created (cloned) object which is changed > exactly like `DateTimeImmutable` > http://php.net/manual/en/datetimeimmutable.add.php > I am aware of what `final` means in other languages, it just seems that everyone then needs to translate back and forth from `final` to `immutable`. In addition to that, `final` has different meaning in inheritance (re-used keyword), so this adds to the confusion for people unfamiliar with the feature. > Ad. 3 it would be awesome if there could be final variables in general, i= t > would be quite stable if no one could change your variable, AFAIK zvals > have IMMUTABLE flag which could be used, don't know it for sure I'm rathe= r > PHP dev than C there would be need some internals guru to ask if it's > posiible. > > P.S. We've meet on PHPCon'15 in Poland, thanks for +1. > YW! > > Cheers, > -- > Micha=C5=82 Brzuchalski (aka brzuchal) > > 2016-04-05 11:13 GMT+02:00 Marco Pivetta : > >> Hi Micha=C5=82, >> >> First of all: +1 to this: very useful for value objects! >> >> A few questions: >> >> * can you re-declare a final property in a sub-class, making it >> therefore non-final? (I have reasons to do that, related with altering >> states via mappers) >> * do we want to use `final`, or `immutable` for these properties? >> `final` seems to just be a confusing term here. >> * is this feature portable to variables in general? I realize that >> adding metadata to ZVals has huge performance implications, but it would= be >> interesting to do that for performance improvements further down the lin= e >> >> Cheers, >> >> >> Marco Pivetta >> >> http://twitter.com/Ocramius >> >> http://ocramius.github.com/ >> >> On 4 April 2016 at 19:53, Micha=C5=82 Brzuchalski >> wrote: >> >>> Hey Internals, >>> >>> I'm new here. I've been wondering / working on adding final properties >>> into >>> PHP lang. >>> >>> This work started once I had the time to read the "Core Java for >>> Impateient" by Cay S. Horstmann >>> and found it very usefull to have final properties like Java. >>> >>> Those properties differ than `const` because they can be set at runtime= - >>> but only once in their lifetime. >>> Such properties could be very usefull in Singletons, ValueObjects etc. >>> impl >>> like: >>> >>> class Money { >>> public final $amount; >>> public final $currency; >>> public function __constructor($amount, $currency) { >>> $this->amount =3D $amount; >>> $this->currency =3D $currency; >>> } >>> } >>> >>> In above example there is even no need for getter because those >>> properties >>> are immutable through >>> the final keyword, it means those properties cannot change their >>> references >>> just like in Java >>> https://en.wikipedia.org/wiki/Final_(Java) >>> >>> I've already started some impl on own fork >>> https://github.com/php/php-src/compare/master...brzuchal:final-properti= es >>> I've got some basics in C programming, don't know yet if I can impl it >>> complex. >>> >>> I was wondering if it is usefull in yours opinion or is it only my >>> impression. >>> >>> I can provide an RFC if it sounds usefull and if I get Wiki karma >>> >>> Thanks >>> -- >>> Micha=C5=82 Brzuchalski (aka brzuchal) >>> >> >> > As an additional question: how will this (eventually) play with typed properties? I am aware that you cannot declare a class named `final`, but that may change in future, so better factor it into any possible outcomes of the RFC. Cheers, Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ --001a11c3409a0d406d052fba1be7--