Here is how you can change your code to use an exception. It also helps to document the circumstances in which an exception occurs.
class test { public static function Payment($orderid, $total) { if (empty($orderid) && empty($total)) { throw new Exception("fail: Missing Data"); } } }
You can also create your own exception class if you want to include additional data in the exception.
class MyException extends Exception{ public $status, $error; public function __construct($status, $error){ parent::__construct("$status: $error"); $this->status = $status; $this->error = $error; } }
source share