$value) { $method = 'set' . str_replace('_', '', ucwords($key, '_')); if (method_exists($this, $method)) { $this->$method($value); } } } public function setId($id): void { $this->id = $id; } public function getId() { return $this->id; } function toArray(): array { $array = []; foreach (self::getFields() as $key) { $method = 'get' . str_replace('_', '', ucwords($key, '_')); if (method_exists($this, $method)) { $array[$key] = $this->$method(); } } return $array; } }