diff --git a/src/Entity/AbstractEntity.php b/src/Entity/AbstractEntity.php index 035e034..a940a1b 100644 --- a/src/Entity/AbstractEntity.php +++ b/src/Entity/AbstractEntity.php @@ -58,8 +58,27 @@ public function build(array $parameters): void foreach ($parameters as $property => $value) { $property = static::convertToCamelCase($property); - if (\property_exists($this, $property)) { + if (!\property_exists($this, $property)) { + continue; + } + + try { $this->$property = $value; + } catch (\Error $error) { + // If the reason for the error was attempting to set a \stdClass + // instance to an array property, try to type cast it to an + // array ourselves. + + $reflectedProperty = new \ReflectionProperty($this, $property); + + if ( + 'array' !== $reflectedProperty->getType()->getName() || + !($value instanceof \stdClass) + ) { + continue; + } + + $this->$property = (array) $value; } } }