From ab3c08bb80cf1046ef2a6776d539471edd6c9151 Mon Sep 17 00:00:00 2001 From: Sergei Tigrov Date: Thu, 23 May 2024 09:48:01 +0700 Subject: [PATCH] Protect `$attributes` property (#341) --- src/Trait/MagicPropertiesTrait.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Trait/MagicPropertiesTrait.php b/src/Trait/MagicPropertiesTrait.php index 89708eb1f..532c638c4 100644 --- a/src/Trait/MagicPropertiesTrait.php +++ b/src/Trait/MagicPropertiesTrait.php @@ -128,7 +128,7 @@ public function __unset(string $name): void if ($this->hasAttribute($name)) { unset($this->attributes[$name]); - if (property_exists($this, $name)) { + if ($name !== 'attributes' && isset(get_object_vars($this)[$name])) { $this->$name = null; } @@ -173,7 +173,7 @@ public function __set(string $name, mixed $value): void public function getAttribute(string $name): mixed { - if (property_exists($this, $name)) { + if ($name !== 'attributes' && property_exists($this, $name)) { return get_object_vars($this)[$name] ?? null; } @@ -266,7 +266,7 @@ public function canSetProperty(string $name, bool $checkVars = true): bool protected function populateAttribute(string $name, mixed $value): void { - if (property_exists($this, $name)) { + if ($name !== 'attributes' && property_exists($this, $name)) { $this->$name = $value; } else { $this->attributes[$name] = $value;