diff --git a/src/Extension/ExtendableTrait.php b/src/Extension/ExtendableTrait.php index 2855d187..f899d669 100644 --- a/src/Extension/ExtendableTrait.php +++ b/src/Extension/ExtendableTrait.php @@ -210,7 +210,6 @@ public function addDynamicProperty($dynamicName, $value = null) self::$extendableGuardProperties = false; array_set($this->extensionData['dynamicProperties'], $dynamicName, $value); - $this->extendableSet($dynamicName, $value); self::$extendableGuardProperties = true; } @@ -419,7 +418,7 @@ public function extendableSet($name, $value) * Setting an undefined property */ if (!self::$extendableGuardProperties) { - $this->{$name} = $value; + array_set($this->extensionData['dynamicProperties'], $name, $value); } } diff --git a/src/Halcyon/Model.php b/src/Halcyon/Model.php index c130823a..4129f5bf 100644 --- a/src/Halcyon/Model.php +++ b/src/Halcyon/Model.php @@ -1603,6 +1603,15 @@ public static function cacheMutatedAttributes($class) static::$mutatorCache[$class] = $mutatedAttributes; } + public function addDynamicProperty($dynamicName, $value = null) + { + if (isset($this->attributes[$dynamicName])) { + return; + } + + $this->setAttribute($dynamicName, $value); + } + /** * Dynamically retrieve attributes on the model. *