__get() and __set() are great, but 90% of the time, I find myself
  using them to create public readonly properties.

I can see where it could come in handy but I honestly think it'd be bloat.
We have to relax with the OO features because the increased code size has already made it harder to maintain and it has the potential to make PHP far more complicated than what it should be.

An extension could accomplish this by exporting an interface which overrides the object's read_property() method. One could "flag" which properties are allowed to be accessed r/o by giving them a distinct name e.g.:

class foo implements ReadOnlyProperties {
   private $__ro__bar;
   function __construct($val) {
       $this->__ro__bar = $val;
   }
}

$f = new foo(123);
var_dump($f->bar);

The special getter sees that bar isn't in the properties table and looks for __ro__bar instead (overriding visibility restrictions in the process). Since there's no write_property override, the prop remains unwritable from outside of the object.

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

Reply via email to