Hey Internals,

I'm new here. I've been wondering / working on adding final properties into
PHP lang.

This work started once I had the time to read the "Core Java for
Impateient" by Cay S. Horstmann
and found it very usefull to have final properties like Java.

Those properties differ than `const` because they can be set at runtime -
but only once in their lifetime.
Such properties could be very usefull in Singletons, ValueObjects etc. impl
like:

class Money {
    public final $amount;
    public final $currency;
    public function __constructor($amount, $currency) {
        $this->amount = $amount;
        $this->currency = $currency;
    }
}

In above example there is even no need for getter because those properties
are immutable through
the final keyword, it means those properties cannot change their references
just like in Java
https://en.wikipedia.org/wiki/Final_(Java)

I've already started some impl on own fork
https://github.com/php/php-src/compare/master...brzuchal:final-properties
I've got some basics in C programming, don't know yet if I can impl it
complex.

I was wondering if it is usefull in yours opinion or is it only my
impression.

I can provide an RFC if it sounds usefull and if I get Wiki karma

Thanks
--
Michał Brzuchalski (aka brzuchal)

Reply via email to