Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:99669 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 84527 invoked from network); 29 Jun 2017 02:57:17 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Jun 2017 02:57:17 -0000 Authentication-Results: pb1.pair.com smtp.mail=kalle.php@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=kalle.php@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.174 as permitted sender) X-PHP-List-Original-Sender: kalle.php@gmail.com X-Host-Fingerprint: 209.85.223.174 mail-io0-f174.google.com Received: from [209.85.223.174] ([209.85.223.174:36500] helo=mail-io0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D1/27-07609-B8C64595 for ; Wed, 28 Jun 2017 22:57:16 -0400 Received: by mail-io0-f174.google.com with SMTP id z62so46307101ioi.3 for ; Wed, 28 Jun 2017 19:57:15 -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=YV6WDH12w9mDE2DMd/dLb1kUOjfpKD5dB42xsPMH0Is=; b=t2DOphTWZD2d8dE5jVcTXQJuXJFDYfXBysvTTSBpXn9K2jKt6wJM9Ot5j38Uxnl9Bu p+lN6reGYc8cQ5Aj/DxnBl9oIHKxt7e0Yj9SltiZPC9NaoHT7jrGyai0eb8EsEdI5WNs tlsoFVU0wxaqofSINv5o8hqYscLK0FHgI1dfSB4EGA3Dbrt6qrOLEF60Xs0zP+V78FSM oDwhgyXcqsomZ+j11zetZ7IYAT+BbCWjGTSKKzbjt/8CqZN0ArksC+gFq4QmesLv6z+R p+BTALZRJKZb7UClsmIRCmkh+fq2M6Ir6nJ//uWaDeuBnxgHwwNv4/fB5N1kkfzDA9J7 iVWA== 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=YV6WDH12w9mDE2DMd/dLb1kUOjfpKD5dB42xsPMH0Is=; b=Mu+M0itiVtUedLVSRrbv1Rr7FqsrtomlDGKuTPTCq6FeIBPVolOGU/yVeCpjRHDJ89 RYPoewfvCG0zoAaQUqY/Ne4qlQNXt1hLkejifoynX3A8D3lXXSGjo6m/KSYmzoR7cXbP tB32+c8P+B3WRydICePRPSydDY2mR3iiXEnKlWadT0fMNaxox7kx64TaMHrpUlCCC9R9 dhbK58tegPa+CzYMh2qQpETN468TYiPMJZNW03vRVsNGgHeZh1j5oGSmM+1cAc2qCl3P MCVOJGUJUKw6Yy2tYc32nYc1KBB3bT794QGFQeN3J5EAsY2XCChwLs589Lj15QVGx7Nt YaRg== X-Gm-Message-State: AKS2vOyhE4yi6aL/tkysieFSTcIrpwIMjw6iBLCSEg4NzWoVLkGE21KV nrwtIsDwFGEBU+rjbXr4yMjTfLuBkw== X-Received: by 10.107.3.225 with SMTP id e94mr16843090ioi.64.1498705032660; Wed, 28 Jun 2017 19:57:12 -0700 (PDT) MIME-Version: 1.0 Sender: kalle.php@gmail.com Received: by 10.107.150.196 with HTTP; Wed, 28 Jun 2017 19:57:12 -0700 (PDT) In-Reply-To: References: Date: Thu, 29 Jun 2017 04:57:12 +0200 X-Google-Sender-Auth: UoMbTkfxGoZelZ_vtMGHkp_ew7g 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) 2017-06-29 1:07 GMT+02:00 David Rodrigues : > readonly $number = mt_rand(); > I 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. 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. 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: class A { protected readonly $b; public function __construct() { $this->b = 'C'; } } class B extends A { public function read() { echo $this->b; } public function write() { $this->b = 'D'; } } $b = new B; $b->read(); // "C" $b->write(); // <- error -- regards, Kalle Sommer Nielsen kalle@php.net