On Mon, Jul 16, 2012 at 2:59 PM, Anthony Ferrara <ircmax...@gmail.com>wrote:
> Ferenc, > > On Mon, Jul 16, 2012 at 8:25 AM, Ferenc Kovacs <tyr...@gmail.com> 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 (const >> 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 reason >> 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 not > make it final for the entire engine (meaning that I can declare a global > property as final using `final $var = 1;`)... Thereby making this a rather > 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) -- Ferenc Kovács @Tyr43l - http://tyrael.hu