hasProperty('id')) { $parent = $reflection->getParentClass(); if ($parent === false) { throw new \ReflectionException(sprintf('Property %s::$id does not exist', $entity::class)); } $reflection = $parent; } $reflection->getProperty('id')->setValue($entity, $id); return $entity; }