Re: RFC: Locked Classes

From: Date: Sun, 10 Mar 2019 20:56:43 +0000
Subject: Re: RFC: Locked Classes
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-104635@lists.php.net to get a copy of this message
On 10/03/2019 20:19, Dan Ackroyd wrote:
trait LockedClass { public function __set($name, $value) { throw new \Exception("Property [$name] doesn't exist for class [" . get_class($this) . "] so can't set it"); } public function __get($name) { throw new \Exception("Property [$name] doesn't exist for class [" . get_class($this) . "] so can't get it"); } }
Incidentally, this isn't quite equivalent to the current RFC, because it will also intercept access to private or protected properties from out of scope. It doesn't make much difference other than making the error messages less helpful, but it's an example of how a nice userland implementation isn't quite as trivial as it first looks. Regards, -- Rowan Collins [IMSoP]

« previous php.internals (#104635) next »