FIX Prevent infinite loops in Deprecation::notice()

This commit is contained in:
Steve Boyd 2022-10-13 13:37:29 +13:00
parent 906cd0e76d
commit 1ee0aff1d1

View File

@ -67,6 +67,8 @@ class Deprecation
*/ */
protected static $module_version_overrides = []; protected static $module_version_overrides = [];
protected static bool $inside_notice = false;
/** /**
* @var int - the notice level to raise on a deprecation notice. Defaults to E_USER_DEPRECATED if that exists, * @var int - the notice level to raise on a deprecation notice. Defaults to E_USER_DEPRECATED if that exists,
* E_USER_NOTICE if not * E_USER_NOTICE if not
@ -171,10 +173,16 @@ class Deprecation
*/ */
public static function notice($atVersion, $string = '', $scope = Deprecation::SCOPE_METHOD) public static function notice($atVersion, $string = '', $scope = Deprecation::SCOPE_METHOD)
{ {
if (static::$inside_notice) {
return;
}
static::$inside_notice = true;
// try block needs to wrap all code in case anything inside the try block
// calls something else that calls Deprecation::notice()
try {
if (!static::get_enabled()) { if (!static::get_enabled()) {
return; return;
} }
$checkVersion = self::$version; $checkVersion = self::$version;
// Getting a backtrace is slow, so we only do it if we need it // Getting a backtrace is slow, so we only do it if we need it
$backtrace = null; $backtrace = null;
@ -238,6 +246,9 @@ class Deprecation
user_error($string ?? '', $level ?? 0); user_error($string ?? '', $level ?? 0);
} }
} }
} finally {
static::$inside_notice = false;
}
} }
/** /**