Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:99659 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 48052 invoked from network); 28 Jun 2017 17:37:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Jun 2017 17:37:44 -0000 Authentication-Results: pb1.pair.com smtp.mail=me@kelunik.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=me@kelunik.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain kelunik.com from 81.169.146.216 cause and error) X-PHP-List-Original-Sender: me@kelunik.com X-Host-Fingerprint: 81.169.146.216 mo4-p00-ob.smtp.rzone.de Received: from [81.169.146.216] ([81.169.146.216:19838] helo=mo4-p00-ob.smtp.rzone.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 70/03-07609-069E3595 for ; Wed, 28 Jun 2017 13:37:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1498671454; l=6222; s=domk; d=kelunik.com; h=Content-Type:Cc:To:Subject:Date:From:References:In-Reply-To: MIME-Version; bh=BrUozc5l2XpfmjC1AY64AY2FxDqY9zNqNPaGJaAyc9A=; b=eA5KD4OADE2SvpuUWshzZrQ/ywTuedva9uHnYRGt/dDmn2T5tTITSF8TgVID47Wr4u C0ncc2W6ldSJlL21luJ0U2+9/Bqt8w6q+rqN71nceOX6fN8Y/cORl+dFJoMUlUnnUb4r D85P0FcodoXNNglh2UFGZK5yK8MOSZOUVKySs= X-RZG-AUTH: :IWkkfkWkbvHsXQGmRYmUo9mls2vWuiu+7SLDup6E67mzuoNHBqX83Q== X-RZG-CLASS-ID: mo00 Received: by mail-oi0-f44.google.com with SMTP id l83so47388654oif.1 for ; Wed, 28 Jun 2017 10:37:33 -0700 (PDT) X-Gm-Message-State: AKS2vOz/wauVqgvoFcQ+NBf68Czp0mgMAmehRa6JKbCf62tMTW44Z8T7 ZYoBVD6PZYVcZrYexH+79Czm1fGj1Q== X-Received: by 10.202.206.23 with SMTP id e23mr7218668oig.168.1498671453298; Wed, 28 Jun 2017 10:37:33 -0700 (PDT) MIME-Version: 1.0 Received: by 10.74.81.135 with HTTP; Wed, 28 Jun 2017 10:37:32 -0700 (PDT) In-Reply-To: References: Date: Wed, 28 Jun 2017 19:37:32 +0200 X-Gmail-Original-Message-ID: Message-ID: To: Kalle Sommer Nielsen Cc: David Rodrigues , PHP Internals Content-Type: multipart/alternative; boundary="001a113ac7249bec2f055308a35d" Subject: Re: [PHP-DEV] Final variables From: me@kelunik.com (Niklas Keller) --001a113ac7249bec2f055308a35d Content-Type: text/plain; charset="UTF-8" 2017-06-28 18:59 GMT+02:00 Kalle Sommer Nielsen : > Hi David > > 2017-06-28 18:10 GMT+02:00 David Rodrigues : > > Hello internals, > > > > Java supports the "final" keyword before a variable to determines that > this > > variables never change it reference. If I declare a variable as "final", > I > > can only initialize that once, then I could not change it after (but I > can > > manipulate the instance, without issues). > > > > There some special reason to PHP doesn't supports things like that? > > It seems like what you are looking for here is actually a constant[1]. > However constants do not support non scalar types, such as array or > objects, Arrays are supported, but not objects. Regards, Niklas > what would really solve it on the objects side of things > would be the introduction of a "readonly" keyword or similar, like > that of C#[2] > > > final $number = 123; > > $number = 456; // Error: you change change final variables. > > > > final $object = new stdClass; > > $object->allowed = true; // No error. > > > > This feature make sense because it tells to dev that the variable value > > could not be updated directly (new reference). Which make easy to > identify > > when a variable is modifiable or not. > > > > It is valid for a RFC? > > > > - It can uses the "final" keyword; > > - It doesn't a BC; > > Anything is usually valid for an RFC, however I think (personally) > that this should rather be an RFC for a readonly keyword if anything > > > I too think that a final variable can be useful to make some internal > > improvements on language (but it could be a BC for PHP internals). I > mean, > > as the variable could not be modified, then it don't need be a "flexible" > > type internally (I guess that it is a zval, right?). > > > > Reference: https://github.com/kalessil/phpinspectionsea/issues/363 > > > > -- > > David Rodrigues > > > [1] http://php.net/constants > [2] https://docs.microsoft.com/en-us/dotnet/csharp/language- > reference/keywords/readonly > > -- > regards, > > Kalle Sommer Nielsen > kalle@php.net > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --001a113ac7249bec2f055308a35d--