Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:99664 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 57624 invoked from network); 28 Jun 2017 18:47:28 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Jun 2017 18:47:28 -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.176 as permitted sender) X-PHP-List-Original-Sender: david.proweb@gmail.com X-Host-Fingerprint: 209.85.192.176 mail-pf0-f176.google.com Received: from [209.85.192.176] ([209.85.192.176:34436] helo=mail-pf0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E8/B4-07609-8B9F3595 for ; Wed, 28 Jun 2017 14:47:23 -0400 Received: by mail-pf0-f176.google.com with SMTP id s66so37704565pfs.1 for ; Wed, 28 Jun 2017 11:47:20 -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=ONawAECUAO6MyopEsci2d4VZlB7bURDKKTiaPPLXeGw=; b=KTwmn354alRrJc9rROkqIMpqsHSVHhFHDzIibAgcn7gaNnj+Q0UoEHqkR2z2RRZK4i scKgM9Xt2KnI+rnA3xlEJjudCjfTZzx65YXL+9rml7wPUhlIMtrUKJQ3/EPhiI1s50ua ZrTDLqX4g4eDjWe9y6sWkgYdtB2E4cj3Jh7lF88BopI3eByf/eZliYz/2+iI4ZHv17TP z5Sng/M3dr0lf90e6CuOh9I+bt6u/mbHvWohcZl1gbEUlH0AXHNCe6C+sS31n/toC9ys HIWB7eC1nef7zP/DQ+EW3rDV8Mux5haJXXk2kMrdfE7TDu4GzY0DXuQ2j5c+jO2TmzLC CPcw== 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=ONawAECUAO6MyopEsci2d4VZlB7bURDKKTiaPPLXeGw=; b=oxOuIIomrutc306Nj74Air7UuGZeowrIoUQOd4ln6pegsZdDJSMs/MR828d2Em+dI+ Pq7KjwfyzWNR8Rhi3tI3c94UtgcOrEY3h8PeNUVikh6mfTYbxI/kCfccRpegrrdNscsp WfQigMPsmWUfZYOt3V3D4ioXCqvB76QHnIcUxRP75iG7DBNWuG+yzJMzlyKv+kDQ1XXg ABWMgzg2hNnieJrqSjxeAdsvZc6gNyYF8AKkNgHmx1GIYIzWsj7EwyXI/P4bj0q7uN3P 7ukClrEZtrUQAt9jkRatahUtEQNl9gFVhtD4ItqyMoFUT+qvDBrDIkCsmdiNSmlfci68 orsQ== X-Gm-Message-State: AKS2vOy3kVyHEQ6sN1BjofY6VMp5eAzgb2tAUQX5BVjjcMZ3zIC+SUiu O/rhebkJiO40ZQ8WfeKk96exI5llujQj X-Received: by 10.99.146.88 with SMTP id s24mr11596843pgn.85.1498675637954; Wed, 28 Jun 2017 11:47:17 -0700 (PDT) MIME-Version: 1.0 Received: by 10.100.181.138 with HTTP; Wed, 28 Jun 2017 11:46:57 -0700 (PDT) In-Reply-To: References: Date: Wed, 28 Jun 2017 15:46:57 -0300 Message-ID: To: Kalle Sommer Nielsen Cc: PHP Internals Content-Type: multipart/alternative; boundary="f403045e337208ad100553099d1e" Subject: Re: [PHP-DEV] Final variables From: david.proweb@gmail.com (David Rodrigues) --f403045e337208ad100553099d1e Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 2017-06-28 13:59 GMT-03:00 Kalle Sommer Nielsen : > Hi David > > 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] > =E2=80=8B=E2=80=8B =E2=80=8BNot on reality.=E2=80=8B :( The "final" keyworks make a "local scope" variable value "blocked to rewrite" after instantiate it. Okay, it sounds like a "const", and it is, but "not as we known it". While constants are class member (or globals), a final variable is just a variable blocked to rewrite, and it could be initialized with a new data content every time that the context is called (eg. a function). For instance (note that the parameter is "final", then I can't modify the parameter variable, but it can receives a new value each time that I call this function): function write(final $message) { echo $message; } write("Hello"); write("World"); // Write "Hello World" on ouput. Or then: function randomNumber() { final $number =3D mt_rand(); echo $number; // $number =3D mt_rand_again(); // <-- will not be allowed! } randomNumber(); =E2=80=8B // Write "0.123" randomNumber(); =E2=80=8B // Write "0.456" =E2=80=8B > > [1] http://php.net/constants > [2] https://docs.microsoft.com/en-us/dotnet/csharp/language- > reference/keywords/readonly > --=20 David Rodrigues --f403045e337208ad100553099d1e--