Re: [RFC] Readonly Properties
| From: | Andrea Faulds | Date: | Tue, 28 Oct 2014 14:12:47 +0000 |
| Subject: | Re: [RFC] Readonly Properties | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-78428@lists.php.net to get a copy of this message | ||
> On 28 Oct 2014, at 09:46, Chris Wright <cw@daverandom.com> wrote:
>
> Sorry, but I don't like this. This means that the visibility modifier is no longer next to
> the thing that it applies to,
I wouldn’t say that. The visibility modifier is an aspect of the property itself, not its
implementation. A property can be public-readable and private-writeable regardless of whether
it’s a plain property or is a getter and a setter.
> IMO this is actually harmful to the readability because the order in which the accessors were
> defined then becomes significant
It wouldn’t be significant. The public/private doesn’t apply to the getters and setters, it
applies to reading and writing from the property, regardless of its implementation.
If we did’t enforce order, got the read/write syntax and getters and setters, hypothetically this
would be possible:
public/private $foobar {
set($value) { … }
get { … }
}
However, hopefully coding style guides would discourage that.
> I would suggest something like this:
>
> public $foobar {
> get { return $this->bar * $this->foo; }
> private set($value) { $this->bar = $value / $this->foo }
> }
>
> ...where only a single visibility modifier is permitted on the left, and this is treated as the
> *default* visibility for the accessors, which are free to declare another visibility if they want
I don’t like this, it’s moving the visibility again and having it split between the start and
end of the declaration.
--
Andrea Faulds
http://ajf.me/