<?php final class FullName implements JsonSerializable { public $forename; public $surname; public function __construct(string $forename, string $surname) { $this->forename = $this->validateAndNormalize($forename); $this->surname = $this->validateAndNormalize($surname); } private function validateAndNormalize($name) : string { return ucwords($name); } public function jsonSerialize() { return $this->forename . ' ' . $this->surname; } } $o = new FullName('aaa', 'bbb'); $returnValues = array( 'id' => 42, 'name' => $o, 'message' => 'The professional has been updated' ); echo json_encode($returnValues);
You have javascript disabled. You will not be able to edit any code.