On 25.08.21 12:45, Rowan Tommins wrote:
> * Adding a parent to an existing class isn't always possible, if it
> already inherits from something else. Perhaps the behaviour could also
> be available as a trait, which defined stub __get and __set methods,
> allowing for the replacement of the internal implementation as you've
> described?
>
Couldn't this be easily done in userland with the ArrayLikeObject (an
example in the RFC) or something similar, just done as a trait? Maybe
having an example trait implementation that basically "imitates"
stdClass in terms of dynamic properties would be helpful to show in the
RFC, to highlight a possible resolution path for legacy code with this
problem. This could be an example implementation:
trait DynamicPropertiesTrait
{
   private array $dynamicProperties = [];
   public function &__get(string $name): mixed { return
$this->dynamicProperties[$name]; }
   public function __isset(string $name): bool { return
isset($this->dynamicProperties[$name]); }
   public function __set(string $name, mixed $value): void {
$this->dynamicProperties[$name] = $value; }
   public function __unset(string $name): void {
unset($this->dynamicProperties[$name]); }
}