FirstName = $exploded_name[0]; $this->LastName = $exploded_name[1]; } } /** * Sets the first name of the person. * * @param string $FirstName */ public function setFirstName(string $FirstName): void { $this->FirstName = $FirstName; } /** * Gets the last name of the person. * * @return string */ public function getLastName(): string { return $this->LastName; } /** * Sets the last name of the person. * * @param string $LastName */ public function setLastName(string $LastName): void { $this->LastName = $LastName; } /** * Gets the first name of the person. * * @return string */ public function getFirstName(): string { return $this->FirstName; } /** * Returns a string representation of the person. * * @return string */ public function __toString() { return implode(' ', [$this->FirstName, $this->LastName]); } /** * Returns an array representation of the person * * @return array */ public function toArray(): array { return [ 'first_name' => $this->FirstName, 'last_name' => $this->LastName ]; } /** * Constructs object from an array representation * * @param array $data * @return Person */ public static function fromArray(array $data): Person { $person = new Person(); if(isset($data['first_name'])) $person->FirstName = $data['first_name']; if(isset($data['last_name'])) $person->LastName = $data['last_name']; return $person; } }