Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61294 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 86134 invoked from network); 16 Jul 2012 13:25:57 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Jul 2012 13:25:57 -0000 Authentication-Results: pb1.pair.com header.from=tyra3l@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tyra3l@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.160.42 as permitted sender) X-PHP-List-Original-Sender: tyra3l@gmail.com X-Host-Fingerprint: 209.85.160.42 mail-pb0-f42.google.com Received: from [209.85.160.42] ([209.85.160.42:42468] helo=mail-pb0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DD/E1-11081-46614005 for ; Mon, 16 Jul 2012 09:25:56 -0400 Received: by pbbrp12 with SMTP id rp12so11077794pbb.29 for ; Mon, 16 Jul 2012 06:25:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=iSPuLK7wzPbeGSPSiX5izFqlPv/jrmD4B9VwobkRGd4=; b=W2O7dYVfZER7NrmVrs3lho4bzKTicmZyyAOSUigwNV9peo/Ndd2PU2S2HLnMBnFjnE BUIsR2RlpznvmfsCMG+ijOLp6NAOpNjGLI3c5E6qI0VDkzeRFAGJ+3anAZdYmLv5mB0T BhRFfaqJ3o+8Pxri23cJsBQxPm7fBdlxPIpS0lPSnoJXb5cml7nBJ+Ci7/Et6T3u6B+v SRCs/DYQARtAGMOa70YXLO0CS8gJOWnDtAaf6wXf4cworvmHpI+4d2z/CUgGtkTWsSoX kor9i4Weikie8iLZAJoH220iCrVGcpVEPI+V/jIowe/6YQ8q3lf5a7noPXxxqivReNfE FZUQ== MIME-Version: 1.0 Received: by 10.68.237.74 with SMTP id va10mr26618430pbc.46.1342445153259; Mon, 16 Jul 2012 06:25:53 -0700 (PDT) Received: by 10.68.54.169 with HTTP; Mon, 16 Jul 2012 06:25:53 -0700 (PDT) In-Reply-To: References: Date: Mon, 16 Jul 2012 15:25:53 +0200 Message-ID: To: Anthony Ferrara Cc: PHP Internals Content-Type: multipart/alternative; boundary=047d7b33d0887d91ba04c4f25e24 Subject: Re: [PHP-DEV] supporting the final keyword for properties From: tyra3l@gmail.com (Ferenc Kovacs) --047d7b33d0887d91ba04c4f25e24 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Mon, Jul 16, 2012 at 2:59 PM, Anthony Ferrara wrote= : > Ferenc, > > On Mon, Jul 16, 2012 at 8:25 AM, Ferenc Kovacs wrote: > >> Hi, >> >> The recent >> http://www.mail-archive.com/internals@lists.php.net/msg59301.html >> discussion >> made me wonder why did we decide not supporting the final keywords for >> properties as it would provide an easy way for read-only attributes (con= st >> would be a better choice in performance wise, but then you can only set = it >> in your declaration where no dynamic expression is allowed.) >> >> I would like it to work the same way as it does in java( >> http://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.12.4) >> eg. >> you can set the initial value either in the declaration or later on, but >> after it is set, you can't change it, trying to do that would create a >> recoverable fatal error (or throwing an exception which extends >> RuntimeException). >> >> What do you think? Would this be viable? Is there any still-present reas= on >> why we shouldn't support that? >> > > My question would be where in code would this be enforced? A trivial > implementation could be done in the object.write_property handler. But > wouldn't things like references and the such (read_property and > get_property_ptr_ptr, as well as get_properties) also be paths to > writability? > > Would that then mean that this would need to be added to the zval type > directly, and not just the property table? And if that's the case, why no= t > make it final for the entire engine (meaning that I can declare a global > property as final using `final $var =3D 1;`)... Thereby making this a rat= her > significant engine changes? Or is there an easier way that I'm missing...= ? > > Anthony > Introducting final for the procedural code would be a bad idea imo, but on the other hand it would be in sync with the fact that we added the const keyword to be used in the global scope for example. About whether we should handle it in the zval or in the object.write_property I also don't have a strong opinion, I see both cons and pros. Another thing: If implemented, we should add a few methods to Reflection like: - ReflectionProperty::isFinal(void) - ReflectionProperty::setFinal(bool $final) --=20 Ferenc Kov=C3=A1cs @Tyr43l - http://tyrael.hu --047d7b33d0887d91ba04c4f25e24--