Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:99677 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 14261 invoked from network); 29 Jun 2017 09:59:17 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Jun 2017 09:59:17 -0000 Authentication-Results: pb1.pair.com smtp.mail=david.proweb@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=david.proweb@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.192.169 as permitted sender) X-PHP-List-Original-Sender: david.proweb@gmail.com X-Host-Fingerprint: 209.85.192.169 mail-pf0-f169.google.com Received: from [209.85.192.169] ([209.85.192.169:36273] helo=mail-pf0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CE/BA-07609-17FC4595 for ; Thu, 29 Jun 2017 05:59:15 -0400 Received: by mail-pf0-f169.google.com with SMTP id q86so47925085pfl.3 for ; Thu, 29 Jun 2017 02:59:13 -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=8zLvf1XRm1jW1skB06NuQ2NkJpfiofKYpPzIZl7oO/Q=; b=Fc5mJp/VjekrkpFT7QLUB3Ss7HtgiyScOK1Nc1+xp32M2nrudklsmhFuAbtMRl+Fs6 2dxS/KbY7sISi1KMZmNSYA6iPOrye1O0M6VRYdmh219WdBDpgnRPLvdr9lxw8Miq122F VegbDIL9Ls0nQfN/9u13ezqnmNBSaBz6zRpwg/bhfiPJA8NBB1LQ3pUhUaAD+Imw7NmN RWGtFarkFH2cAjrjH8E0frrCj7PIc2697k1O5V25yW0o1Vpa/nHrTU9cpoVh6enVmHnB Fqbim8N8Is6IL7zvvKLMSdkwUvAh+eJ8nN0iVnvyr3/R5KMCgQVPcg/9ciBeMIes6L5l Qy0w== 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=8zLvf1XRm1jW1skB06NuQ2NkJpfiofKYpPzIZl7oO/Q=; b=WvpMrh/PpBM3OADEOXiXZDPbc4G9A7NM0rGxfn02nMYMhDY7LpLGm61MmGeFa7QGIv 0kTWKJVtLFOKMRa/4WaJwowtBfrEQgs+JS9c/8pZ7g71S5+c/X9ISrcwW+l+0SxPcZdq MwbWakwS8sjdE6qGGf0TyhSGRl8WyToiRinEoUmbHgtLkmMHcja6up/prGKxoovW4Ax8 NjxHv6ksA5HHqNNJaEH+to1jTOJ/Dh61veT09ycWhEbXQwcMehr9bQxAJUYJWPF9lXcq Cb6GLy4nQNU99ncnQs5DyT/7+EqlAuqX5XfOvbSy1wOmQg38ZGq0l35xPj8c36b92XRL 7CxA== X-Gm-Message-State: AKS2vOz01RmEjtvjjrP4BO8rKu/BlGj3zbcKM1E+5WR6gwML9rRvUWJ8 VUkz3UYIsvn/DgtpGOUccFcKtGefPg== X-Received: by 10.84.205.70 with SMTP id o6mr17196395plh.32.1498730350578; Thu, 29 Jun 2017 02:59:10 -0700 (PDT) MIME-Version: 1.0 Received: by 10.100.181.138 with HTTP; Thu, 29 Jun 2017 02:58:49 -0700 (PDT) In-Reply-To: References: <54e9e9f4-1fda-d7db-61a4-2a1574005a79@rhsoft.net> Date: Thu, 29 Jun 2017 06:58:50 -0300 Message-ID: To: Marco Pivetta Cc: "lists@rhsoft.net" , PHP Internals List Content-Type: multipart/alternative; boundary="94eb2c148142290fa20553165ae6" Subject: Re: [PHP-DEV] Final variables From: david.proweb@gmail.com (David Rodrigues) --94eb2c148142290fa20553165ae6 Content-Type: text/plain; charset="UTF-8" I will try answer the questions: > I get that, but I still don't understand why you would forcefully need > it to be a variable still then if you know the value is gonna be > constant, of course besides global visibility or in iterations "final" is not "const". "final" mean a initial state that will never be modified, but it could be initialized with different values on same runtime. It is like I say "my name is David and will be all the time David when I am on an informal context" and "my name is Rodrigues and will be all the time Rodrigues when I am on a forma context", on same "document". https://pastebin.com/QCrmrZQe > 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. It is done on Java, for instance. We can use "final" on classes or functions that mean that it cannot be overrided, or "final" in variables, that mean that it cannot be re-referenced (rewrite after initialization). And not seems strange to me. We could "abstract the term" to understand that in any of cases (for classes, function or variables) the information could not be overrided after defined. > 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: For me, the readonly keyword should be implemented on future to another case: make a public property writeable only by the own class. But it is for another discussion. > 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) I don't know if I understand, but for properties you could redefine a final property on constructor (as Java). https://pastebin.com/bTZcUT33 > * Arrays and resources as properties You can modify arrays or resources on final variables, since that you don't modify the reference. https://pastebin.com/D38wL8x7 > * Named (Factory) constructors I don't understand. > * Property nullability - how do you define if a property was written to the "last valid time" before freezing it Because PHP don't have support to "variable initialization" (eg. "$name;") then you should only initializate it when you will write the initial (and freezed) value. https://pastebin.com/Ua6DFUC1 > * 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 It will be modified. Final variables still are a variable, but with the status that "never change after initializate" (a flag). We can just implement a new reflection method to properties to identify if it isFinal(), or even for variables like "is_final($var)". By other side, this last doesn't make sense because the final variable is just a "code documentation" to the own dev knows that is not allowed modify it anymore. Maybe we need implements that only for ReflectionProperty (first case), because it could be part of a code that the user have not modify access (eg. vendor code). https://pastebin.com/jSjNQACd 2017-06-29 6:25 GMT-03:00 Marco Pivetta : > On Thu, Jun 29, 2017 at 11:19 AM, lists@rhsoft.net > wrote: > > > in other languages like Visual Basic constants are fast, in PHP they are > > slow, both in define and access > > > > Two things here: > > 1. don't ever consider visual basic for any comparison of any sort: it's > basically (ha!) the worst example of a programming language that I can > think of before malborge > 2. speed is not relevant in this scope: program correctness is. Final > properties would allow switching value object representations from accessor > (getter) based logic (extremely slow) to public property based (less > overhead, also in writing). > > Marco Pivetta > > http://twitter.com/Ocramius > > http://ocramius.github.com/ > -- David Rodrigues --94eb2c148142290fa20553165ae6--