I second getting rid of write-onle - the only real case I can think of, is
something like a password property on a user/account model-type, which gets
encrypted and thus can't be read, and as Amaury pointed out, that should be
a setPassword() method instead, perhaps even a separate UserPasswordService
component. Certainly not an accessor.

As for read-only, I strongly advice against overloading the const keyword
with an entirely new meaning, if that's what you're suggesting?

Just drop the idea of read-only altogether, please - it's so marginally
useful in the first place, unconventional compared to other languages, and
will just get in the way. For most properties that only have a
read-accessor, it won't even make any sense for someone to try to extend
that with a write-accessor. And as said, if you want to keep the internal
value safe from write, just declare the actual property as private.

---------- Forwarded message ----------
From: Amaury Bouchard <ama...@amaury.net>
To: Clint Priest <cpri...@zerocue.com>
Cc: "internals@lists.php.net" <internals@lists.php.net>
Date: Sat, 20 Oct 2012 10:09:35 +0200
Subject: Re: [PHP-DEV] [RFC] Accessors v1.1 -> v1.2 Summary
read-only / write-only keywords

"no equivalent replacement has been suggested" => ouch

read-only => const

write-only => shouldn't exists. A write-only accessor is just a method
disguised in property.

It's not a good idea to allow:
    $obj->prop = 3;
when the meaning is:
    $obj->meth(3);

Reply via email to