Skip to content

Commit 01064d1

Browse files
vranadg
authored andcommitted
Describer: checked method/function existence before reflection (#611)
Prevents exception inside exception handler that could kill PHP-FPM silently
1 parent 57c1dde commit 01064d1

1 file changed

Lines changed: 16 additions & 15 deletions

File tree

src/Tracy/Dumper/Describer.php

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -336,23 +336,24 @@ public function getReferenceId(array $arr, string|int $key): ?int
336336
private static function findLocation(): ?array
337337
{
338338
foreach (debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) as $item) {
339-
if (isset($item['class']) && ($item['class'] === self::class || $item['class'] === Tracy\Dumper::class)) {
339+
$reflection = null;
340+
if (isset($item['class'])) {
341+
if ($item['class'] === self::class || $item['class'] === Tracy\Dumper::class) {
342+
$location = $item;
343+
continue;
344+
} elseif (method_exists($item['class'], $item['function'])) {
345+
$reflection = new \ReflectionMethod($item['class'], $item['function']);
346+
}
347+
} elseif (function_exists($item['function'])) {
348+
$reflection = new \ReflectionFunction($item['function']);
349+
}
350+
351+
if (
352+
$reflection?->isInternal()
353+
|| preg_match('#\s@tracySkipLocation\s#', (string) $reflection?->getDocComment())
354+
) {
340355
$location = $item;
341356
continue;
342-
} elseif (isset($item['function'])) {
343-
try {
344-
$reflection = isset($item['class'])
345-
? new \ReflectionMethod($item['class'], $item['function'])
346-
: new \ReflectionFunction($item['function']);
347-
if (
348-
$reflection->isInternal()
349-
|| preg_match('#\s@tracySkipLocation\s#', (string) $reflection->getDocComment())
350-
) {
351-
$location = $item;
352-
continue;
353-
}
354-
} catch (\ReflectionException) {
355-
}
356357
}
357358

358359
break;

0 commit comments

Comments
 (0)