Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:99665 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 69904 invoked from network); 28 Jun 2017 23:07:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Jun 2017 23:07:50 -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.179 as permitted sender) X-PHP-List-Original-Sender: david.proweb@gmail.com X-Host-Fingerprint: 209.85.192.179 mail-pf0-f179.google.com Received: from [209.85.192.179] ([209.85.192.179:33532] helo=mail-pf0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B8/65-07609-2C634595 for ; Wed, 28 Jun 2017 19:07:47 -0400 Received: by mail-pf0-f179.google.com with SMTP id e7so40589373pfk.0 for ; Wed, 28 Jun 2017 16:07:46 -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=VwTvpyVGx5awIOknFKuxEcWEYAQDHs2p8SOO1t3XDUU=; b=qG1t0zyUQl3WsFKexfN1svt+0lmw8qbGqCm4M3Ox8JDq+Q+VTMM62VcpzHDIGAIwlP IajXLXxkZeFIC1fesU49672cWgB7XLaLWf6u1gqaNAhI0au9uhA3i1aw/Z7y98VjY+s8 /NRpoUraxBSZ749tprKZJya07kg8Jt7ZA/lZqk/xeFtrPwcKCpV9DMH1vtsExm3VgFaV tZ6Oo1/vUASPcQA9dFXfUj5xH84jtUrBC2rBSoqF1wCFuyRekIY8YY2fmnyRs5QUphi/ mmtzO5HDRtVxkEXi0XKijArg7yJAo0FjGY51dPmZuW88PC51uqtXpoFIj7H0lBERkkY9 VS+w== 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=VwTvpyVGx5awIOknFKuxEcWEYAQDHs2p8SOO1t3XDUU=; b=fiZ6K4NQJpPJdJ63/fgXaZ1WoByoa5q+Pi3n2yZ4XrQt66zCsRcMn+6tAGbu6LDJb/ 9swf7M5i08TVbqFSURJ3lYgZeMy2IJZP63zgin9SlZhOhz2GDpNQOdNiCFpOtbXx6KCi hHmOXJkAGaZuoq9+wzm1SuYN7KsQ2qaIkXpF4/dtEFsiOQb7X72KZTqQTggrlWoGz2yh c3GXRCDXp2PmkdZbBNT6nI5ME+0GoGhNVLVA/e/soRKeNdRE/wXc802C2jFfFGYlME6X RD8ew0BUwEYebB+hmPFMmhmgj3nTytCm1NyAKba5n0jKgonqfPn7/YLL3kT0YGV7ujN0 PEdw== X-Gm-Message-State: AKS2vOysp9MbKObu0nhHAANV0SOp3UkiYXnzcK8jLAplOKntQDehJ/m0 CTBQK9ImRqYaz4aLNct6bojxZpb5MJ7L X-Received: by 10.98.245.207 with SMTP id b76mr13468422pfm.113.1498691263754; Wed, 28 Jun 2017 16:07:43 -0700 (PDT) MIME-Version: 1.0 Received: by 10.100.181.138 with HTTP; Wed, 28 Jun 2017 16:07:23 -0700 (PDT) In-Reply-To: References: Date: Wed, 28 Jun 2017 20:07:23 -0300 Message-ID: To: Kalle Sommer Nielsen Cc: PHP Internals Content-Type: multipart/alternative; boundary="001a11475b6e67755305530d4012" Subject: Re: [PHP-DEV] Final variables From: david.proweb@gmail.com (David Rodrigues) --001a11475b6e67755305530d4012 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable =E2=80=8B Walter Parker =E2=80=8B wrote:=E2=80=8B > =E2=80=8B Constant may not have been the right word (or idea), but I agree with Kalle. We should use readonly as the keyword here and not final as the keyword. We can keep the same scoping rules so the following would work: >=E2=80=8B =E2=80=8B> function randomNumber() { =E2=80=8B>=E2=80=8B *readonly *$number =3D mt_rand(); =E2=80=8B =E2=80=8BI 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. 2017-06-28 15:46 GMT-03:00 David Rodrigues : > 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-refe >> rence/keywords/readonly >> > > -- > David Rodrigues > --=20 David Rodrigues --001a11475b6e67755305530d4012--