Skip to content

Commit ca05898

Browse files
authored
Merge pull request #853 from cakephp/fix-845
fix PHP8.0+ deprecation warning showing Cake/Core/functions.php as source of deprecation
2 parents 6de421f + 42498c3 commit ca05898

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/Plugin.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,19 @@ public function setDeprecationHandler($service)
9595
$previousHandler = set_error_handler(
9696
function ($code, $message, $file, $line, $context = null) use (&$previousHandler) {
9797
if ($code == E_USER_DEPRECATED || $code == E_DEPRECATED) {
98+
// In PHP 8.0+ the $context variable has been removed from the set_error_handler callback
99+
// Therefore we need to fetch the correct file and line string ourselves
100+
if (PHP_VERSION_ID >= 80000) {
101+
$trace = debug_backtrace();
102+
foreach ($trace as $idx => $traceEntry) {
103+
if ($traceEntry['function'] !== 'trigger_error') {
104+
continue;
105+
}
106+
$file = $trace[$idx + 2]['file'];
107+
$line = $trace[$idx + 2]['line'];
108+
break;
109+
}
110+
}
98111
DeprecationsPanel::addDeprecatedError(compact('code', 'message', 'file', 'line', 'context'));
99112

100113
return;

0 commit comments

Comments
 (0)