Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:99670 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 89987 invoked from network); 29 Jun 2017 04:20:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Jun 2017 04:20:45 -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.128.178 as permitted sender) X-PHP-List-Original-Sender: ocramius@gmail.com X-Host-Fingerprint: 209.85.128.178 mail-wr0-f178.google.com Received: from [209.85.128.178] ([209.85.128.178:34425] helo=mail-wr0-f178.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 88/A7-07609-C1084595 for ; Thu, 29 Jun 2017 00:20:44 -0400 Received: by mail-wr0-f178.google.com with SMTP id 77so183238880wrb.1 for ; Wed, 28 Jun 2017 21:20:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=VT4N/tHynGrFkhOUzszT773jlEDXDxsq6YHZP4tFHTA=; b=q8WsAWlcFZ/ZghBibI0Qsvqbyf07Feov9hP00Wp5CaveCFbGOS4rmNSkMWKP1LQ9vw RJK1pAu5G8Kw5D4AA+a2ycZpV0ClbJseKPS2sNWixPmUOEMjghvmxVu1tUF3F/uJ2aEE K3bfOwS7z4Tr2TxG+sGr4BQLMhOt3HFEJmwhXGsSomSg5pEpayg4f9bmhVy0+JkOIjI4 dv7AHo1JuBZfTniSLuztUImCYscl8wDVAMbiEj+VP0mzUc3ojFIdqUoL8k/p6l9PrJcP GhTFlkO+nD/NkELTSXxjSBr9bQANko62ykeiY7pqk80O3PDoNaljg4zmRMqiZ2KOox/G QvAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=VT4N/tHynGrFkhOUzszT773jlEDXDxsq6YHZP4tFHTA=; b=MRnUA7ZHfP64N84MV/915DZRlUNF4GolgOwn2SRv+8Ywj1cManozs8xgbpV4k3POfN 8iCQVl7Bz/VqGh0OtFkwHnilaWdMQuIS9oE2UhJW8FDg9bwSTmIUq4YsENDuppiL93FH ++epkQ9DygZWevGJG4vIoNfADm+g+qPUAUDsEHsI6eWQ7rCC0RgY3JTFYW0LI2CC+Hjm MSZZOzaUqXa0CiRDUphkNrKW8A4Bn9c1OZa0YTn28cfKLTt+UaIryziNHLQhfh2szxC4 jvuEuC6R/TknyXydLH4WTXYjCRzgGaXUp9sZnOP5xabQeUbiqn/9x6Zb5i5PfvAEUQmW XF1Q== X-Gm-Message-State: AKS2vOxWDXu6mwKJjScp1Nko8q9MfRYwkgSEMyl/ft7PTGAFxM6Gs4Ta wy/I2fNCVxIhoaBoDhWGJP4/7dHE6A== X-Received: by 10.223.142.66 with SMTP id n60mr22503189wrb.188.1498710041560; Wed, 28 Jun 2017 21:20:41 -0700 (PDT) MIME-Version: 1.0 Received: by 10.223.161.155 with HTTP; Wed, 28 Jun 2017 21:20:39 -0700 (PDT) Received: by 10.223.161.155 with HTTP; Wed, 28 Jun 2017 21:20:39 -0700 (PDT) In-Reply-To: References: Date: Thu, 29 Jun 2017 06:20:39 +0200 Message-ID: To: Kalle Sommer Nielsen Cc: David Rodrigues , PHP Internals List Content-Type: multipart/alternative; boundary="f403045d599ca60ef40553119f5d" Subject: Re: [PHP-DEV] Final variables From: ocramius@gmail.com (Marco Pivetta) --f403045d599ca60ef40553119f5d Content-Type: text/plain; charset="UTF-8" The `final` modifier would likely clash with property type definitions, if those ever make it to the language. Still, a few pain-points remain: * References to properties (you cannot reference final properties anymore, and that is effectively a BC break for anything using reflection and closure scope binding) * Arrays and resources as properties * Named (Factory) constructors * Property nullability - how do you define if a property was written to the "last valid time" before freezing it * Unset properties and providing an alternative mechanism to distinguish "uninitiated", "undefined" and "frozen" in he event of final properties usage, without breaking current property access semantics This is the exact same set of problems we had with the typed properties RFC, and which caused the RFC to fail: please take all these in consideration while designing the feature. On 29 Jun 2017 4:57 AM, "Kalle Sommer Nielsen" wrote: > 2017-06-29 1:07 GMT+02:00 David Rodrigues : > > readonly $number = mt_rand(); > > I agree that "readonly" is a better keyword, but we have to points here: > > 1. "final" is used on some language (Java, C++ I guess); > > 2. "final" keyword does exists on PHP with a "similar" behaviour; > > > If we can implements "readonly" is good too, because turn it more > implicit. > True we could re-use the final keyword, but think about it this way, > we got final methods and final classes which means it cannot be > overridden/extended respectively, if the final keyword then would also > apply to variables but it would mean they could not be written to, > that would create a WTF-factor. > > The readonly keyword would work for any visibility modifiers, so > inherited classes or extending classes may read a protected property, > but not modify it as well: > > class A { > protected readonly $b; > > public function __construct() { > $this->b = 'C'; > } > } > > class B extends A { > public function read() { > echo $this->b; > } > > public function write() { > $this->b = 'D'; > } > } > > $b = new B; > > $b->read(); // "C" > $b->write(); // <- error > > > -- > regards, > > Kalle Sommer Nielsen > kalle@php.net > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --f403045d599ca60ef40553119f5d--