# internals Digest 20 Oct 2012 09:49:39 -0000 Issue 2820

- Thread: https://externals.io/message/63567
- Original archive: https://news-web.php.net/php.internals/63567
- Started by Rasmus Schultz on 2012-10-20T14:45:17+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #63567 — Rasmus Schultz — 2012-10-20T14:45:17+00:00

URL: https://externals.io/message/63567#63567

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 <amaury@amaury.net>
To: Clint Priest <cpriest@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);

---

## #63569 — Steve Clay — 2012-10-20T18:56:27+00:00

URL: https://externals.io/message/63567#63569 · In reply to: #63567

> Just drop the idea of read-only altogether, please - it's so marginally
> useful in the first place, unconventional compared to other languages, and

Read-only is perfect for value objects, where the alternative is a bunch of protected 
props and getters:

$color = new Color(255, 0, 0);
$color->r;

Steve
-- 
http://www.mrclay.org/
