Re: RFC: Locked Classes
| From: | Gabriel O | Date: | Tue, 12 Mar 2019 21:45:55 +0000 |
| Subject: | Re: RFC: Locked Classes | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-104685@lists.php.net to get a copy of this message | ||
It was already addressed how using such trivial solution is insufficient, please read whole thread
> On 12. Mar 2019, at 22:40, Stanislav Malyshev <smalyshev@gmail.com> wrote:
>
> 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
> smalyshev@gmail.com
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>