On 12/03/2019 21:40, Stanislav Malyshev wrote:
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!");
}
}
Almost...
Magic methods are run both for undefined properties and out-of-scope
ones, so at the very least this leads to unhelpful or vague error messages.
It also doesn't handle unset in the same way as the current RFC, because
it won't affect unsetting a property that was previously defined
(although that part of the RFC is slightly controversial, it seems).
There may be other edge cases it doesn't handle the same way an internal
implementation would, as well, I'm not sure.
It's certainly not a major saving over hacking it together in userland,
but nor is it a major weight to add it to the language. I think having a
well-thought-out implementation built in (either the one in the current
RFC, or a declare directive as has been suggested elsewhere) would
encourage people to use it, and generally be more user-friendly.
Regards,
--
Rowan Collins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php