Skip to content

Commit

Permalink
FIX Prevent infinite loops in Deprecation::notice()
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Oct 11, 2022
1 parent 906cd0e commit 0b2f2d5
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/Dev/Deprecation.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class Deprecation
*/
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,
* E_USER_NOTICE if not
Expand Down Expand Up @@ -171,10 +173,13 @@ public static function set_enabled($enabled)
*/
public static function notice($atVersion, $string = '', $scope = Deprecation::SCOPE_METHOD)
{
if (static::$inside_notice) {
return;
}
static::$inside_notice = true;
if (!static::get_enabled()) {
return;
}

$checkVersion = self::$version;
// Getting a backtrace is slow, so we only do it if we need it
$backtrace = null;
Expand Down Expand Up @@ -232,12 +237,17 @@ public static function notice($atVersion, $string = '', $scope = Deprecation::SC

$string .= " Called from " . self::get_called_method_from_trace($backtrace, 2) . '.';

if ($caller) {
user_error($caller . ' is deprecated.' . ($string ? ' ' . $string : ''), $level ?? 0);
} else {
user_error($string ?? '', $level ?? 0);
try {
if ($caller) {
user_error($caller . ' is deprecated.' . ($string ? ' ' . $string : ''), $level ?? 0);
} else {
user_error($string ?? '', $level ?? 0);
}
} finally {
static::$inside_notice = false;
}
}
static::$inside_notice = false;
}

/**
Expand Down

0 comments on commit 0b2f2d5

Please sign in to comment.