Hi!
> While it can be useful, the ability to set an object property which is
> not part of the class definition can also lead to subtle bugs. Banning
> this for all objects would be a significant and painful breaking change,
> so I propose instead the option to mark a particular class with a new
> keyword, "locked".
Isn't it just:
trait Locked {
public function __set($name, $value) {
throw new RuntimeException("Property $name not declared!");
}
public function __get($name) {
throw new RuntimeException("Property $name not declared!");
}
public function __unset($name) {
throw new RuntimeException("Property $name not declared!");
}
}
The RFC says:
While this can be achieved through strategic use of the __set, __get,
and __unset magic methods, this is long-winded, hard to optimise, and
interferes with other uses of those methods.
I don't see how it's "long-winded" - it's just three one-liners, I don't
see how "interferes with other uses" of these methods (if you want other
uses, just add code to the method), and as for optimization, I think we
already have optimization for pre-declared properties, and if you don't
use any others, it would work just as well.
--
Stas Malyshev
[email protected]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php