Re: [PHP-DEV] Re: internals Digest 20 Oct 2012 09:49:39 -0000 Issue 2820

2012-10-20 Thread Steve Clay

On 10/20/12 10:45 AM, Rasmus Schultz wrote:

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/

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DEV] Re: internals Digest 20 Oct 2012 09:49:39 -0000 Issue 2820

2012-10-20 Thread Rasmus Schultz
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 
To: Clint Priest 
Cc: "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);