Skip to content

Commit 4ef5380

Browse files
committed
* PEAR::isError accepts second parameter that will be matched against
the error code. PEAR::isError($obj, FOO) will return true if $obj is an error object, and $obj->getCode() returns FOO.
1 parent cab18bc commit 4ef5380

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

pear/PEAR.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,13 @@ function registerShutdownFunc($func, $args = array())
226226
* @access public
227227
* @return bool true if parameter is an error
228228
*/
229-
function isError($data) {
230-
return (bool)(is_object($data) &&
231-
(get_class($data) == 'pear_error' ||
232-
is_subclass_of($data, 'pear_error')));
229+
function isError($data, $code = null)
230+
{
231+
if (is_object($data) && (get_class($data) == 'pear_error' ||
232+
is_subclass_of($data, 'pear_error'))) {
233+
return $code === null ? true : $data->getCode() == $code;
234+
}
235+
return false;
233236
}
234237

235238
// }}}

0 commit comments

Comments
 (0)