Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:99658 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 45273 invoked from network); 28 Jun 2017 17:00:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Jun 2017 17:00:07 -0000 Authentication-Results: pb1.pair.com header.from=kalle.php@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=kalle.php@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.42 as permitted sender) X-PHP-List-Original-Sender: kalle.php@gmail.com X-Host-Fingerprint: 209.85.214.42 mail-it0-f42.google.com Received: from [209.85.214.42] ([209.85.214.42:36015] helo=mail-it0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DD/92-07609-A80E3595 for ; Wed, 28 Jun 2017 12:59:56 -0400 Received: by mail-it0-f42.google.com with SMTP id m68so33021408ith.1 for ; Wed, 28 Jun 2017 09:59:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=H2thYvS52fXrrEhVb91piO9+ujhNOoy1mXJ8ytnJDRQ=; b=rcO5rZwvWUAwQXYZ2SmaT8r5GjXlNKrgfRjHRsxl8L6lIViQM0087I/7bEIAYNIBcE yuHlujIrn0YJPy4aU4gizFXNANw9RwTephYhawfEQ0LiQ0qn7jGAj3Ln/QayZZzs+YZv jiXA396Q+5z+IyBu3n8miKfj63y83HZn8LiREpKerQ+95BEsTvCDcRa5sIDD/oqRwgbD Vj0hXiebLVfRqlGuCgExFJ0TZTW7BBDVJ/z+qXvL1BCnFAlQHSf8sjUBXtPGRimTVZVx EaDCIflnUJMW+Zl7f5GJwSjS6xp3s0rz0jd1N9L5KkJcRMqJFrlvu1GaXsR3ZiRQSvK8 30yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=H2thYvS52fXrrEhVb91piO9+ujhNOoy1mXJ8ytnJDRQ=; b=nCb+LPKu5s5wa1iGjIbaW9xr0rToDHjGbVwLKCNLZ45qDr8hofyngwCq9+wfIh1For BbpyP+TFvNJZRMvmlVWfXpHfs1DIlnQ7Zc0RJqSXNABDpv+UZfMpdJyJ2v1eRXTCd1Dy h0BDmY3iSlwhnK8HqV+4rt0dWP2yM4w5U+lZC25xJTud5ZlZelhADMJ4VrKi2rYHJCEO rwszZgCKOdr2/2q3zDAfvO5NvgHdMk+ZXVVbqi0jyyxv2Lp5HGgVQ5U0t6dIHAWVJedM 20KRKbG/Dx78qtdoyj22gLGVYIz/++AEmL4OsjOLB/yv9NBs1xYQ4cfiwjxAw6yAhC78 cipw== X-Gm-Message-State: AKS2vOwFYz9GJZfwUXtuabluQOJlB2m2LjCe3W6Xa2fQikSCHwPczXsN YGwRahwKRtJQvgLq7z8VXLNc9RflGPxK X-Received: by 10.36.40.145 with SMTP id h139mr9018684ith.84.1498669191742; Wed, 28 Jun 2017 09:59:51 -0700 (PDT) MIME-Version: 1.0 Sender: kalle.php@gmail.com Received: by 10.107.180.3 with HTTP; Wed, 28 Jun 2017 09:59:51 -0700 (PDT) In-Reply-To: References: Date: Wed, 28 Jun 2017 18:59:51 +0200 X-Google-Sender-Auth: yivsMK8vhhBVQ3PQ8NeFTkXVAeE Message-ID: To: David Rodrigues Cc: PHP Internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] Final variables From: kalle@php.net (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, 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