On 27/10/2014 20:27, Andrea Faulds wrote:
Tentative syntax. But this way, the visibility stays on the left. I think 
that’s good for readability. If you omit the second specifier, then the first 
one applies to getting and setting, as now. If you include it, the first one 
applies to getting, the second one to setting.

It’d also be compatible with properties, too:

     public/private $foobar {
         get { return $this->bar * $this->foo; }
         set($value) { $this->bar = $value / $this->foo; }
     }

It doesn’t prevent truly read-only properties, either:

     public $foobar {
         get { return $this->bar * $this->foo; }
     }

Does this sound like a good idea? A similar idea came up in the discussions 8 
years ago on readonly.

I like it, except for the fact that if you add a custom getter to a property suddenly it becomes readonly unless you remember to add "; set" to the end of the block, right?

How about this instead for readonly:

      public $foobar {
          get { return $this->bar * $this->foo; }; readonly
      }

And if the flag isn't there, set is implicitly present.

That'd mean you also can keep "public readonly $foobar;" as a shorthand for readonly properties without custom getter.

Cheers

--
Jordi Boggiano
@seldaek - http://nelm.io/jordi

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

Reply via email to