Fix accidental exception instantiation loop

This commit is contained in:
J. King 2019-12-12 21:06:05 -05:00
parent 3c7a76bce1
commit 362bb00158

View file

@ -54,7 +54,9 @@ class Exception extends \Exception {
10701 => 'Method %1$s::%2$s has been disabled from %1$s'];
public function __construct(int $code, ...$args) {
assert(isset(static::$message[$code]), new Exception(self::INVALID_CODE));
if (!isset(static::$messages[$code])) {
throw new Exception(self::INVALID_CODE);
}
$message = static::$messages[$code];
$previous = null;
@ -73,8 +75,10 @@ class Exception extends \Exception {
$count = count(array_unique($matches[1]));
// If the number of replacements don't match the arguments then oops.
assert(count($args) === $count, new Exception(self::INCORRECT_PARAMETERS_FOR_MESSAGE, $count));
if (count($args) !== $count) {
throw new Exception(self::INCORRECT_PARAMETERS_FOR_MESSAGE, $count);
}
if ($count > 0) {
// Go through each of the arguments and run sprintf on the strings.
$message = call_user_func_array('sprintf', array_merge([$message], $args));