From: Kevin Day Date: Sat, 3 Feb 2018 03:51:46 +0000 (-0600) Subject: Bugfix: set_error() must accept an array of errors X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=603ff7b2d9786bad50b054b43d60c76dded5bd42;p=koopa Bugfix: set_error() must accept an array of errors This is considered a bug because the current design of get_error() returns an array if errors. Prior to this, calling set_error($some_class->get_error()) would result in no error being reported because the array value gets ignored. With this change, the entire array contents are appended, only if the given array value is a valid error class instance. --- diff --git a/common/base/classes/base_return.php b/common/base/classes/base_return.php index 669a450..6008dfa 100644 --- a/common/base/classes/base_return.php +++ b/common/base/classes/base_return.php @@ -320,10 +320,11 @@ class c_base_return { /** * Assign the error code. * - * @param null|c_base_error $error + * @param null|c_base_error|array $error * The error code class defining what the error is. * Setting this to NULL will clear all errors. - * @param null|int $delta + * May be an array of c_base_error objects, in which case $delta is ignored. + * @param null|int|bool $delta * (optional) When an integer, the error is assigned an explicit position in the errors array. * When NULL, the error is appended to the errors array. * @@ -331,7 +332,7 @@ class c_base_return { * TRUE on success, FALSE otherwise. */ public function set_error($error, $delta = NULL) { - if (!is_null($error) && !($error instanceof c_base_error)) { + if (!is_null($error) && !($error instanceof c_base_error || is_array($error))) { return FALSE; } @@ -344,7 +345,15 @@ class c_base_return { $this->errors = []; } - if (is_null($delta)) { + if (is_array($error)) { + foreach ($error as $error_object) { + if ($error_object instanceof c_base_error) { + $this->errors[] = $error_object; + } + } + unset($error_object); + } + elseif (is_null($delta)) { $this->errors[] = $error; } elseif (is_int($delta) && $delta >= 0) {