Code = $code; $this->Name = $name; $this->Description = $desc; } // Getter for error code public function GetCode (): int { return $this->Code; } // Getter for error name public function GetName (): string { return $this->Name; } // Getter for error description public function GetDescription (): string { return $this->Description; } // Stringify error public function Stringify (): string { if (isset($this->Description)) return "error " . $this->Name . " (" . strval($this->Code) . "): " . $this->Description; else return "error " . $this->Name . " (" . strval($this->Code) . ")"; } } // Return type of API method final class ReturnT { private ErrorT $ErrorObj; private $Data; // Ctor public function __construct($data = null, int $err_code = 0, string $err_name = "", string $err_desc = "") { $this->ErrorObj = new ErrorT($err_code, $err_name, $err_desc); $this->Data = $data; } // Setter/getter for data public function SetData ($d) { $this->Data = $d; } public function GetData () { return $this->Data; } // Get string representation of error public function GetError (): string { return $this->ErrorObj->Stringify(); } // Is there any error public function IsError (): bool { return $this->ErrorObj->GetCode() !== E_NOERROR; } // Throw JSON error function ThrowJSONError () { JSON_ReturnError( $this->ErrorObj->GetCode(), $this->ErrorObj->GetName(), $this->ErrorObj->Stringify() ); } } ?>