Skip to content

Commit 627fd5e

Browse files
committed
Ignore errors in CachingVisitor when getting the actual value of a constant
1 parent 4e4a5f7 commit 627fd5e

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/SourceLocator/SourceStubber/PhpStormStubs/CachingVisitor.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
use function explode;
2121
use function in_array;
2222
use function is_resource;
23+
use function restore_error_handler;
24+
use function set_error_handler;
2325
use function sprintf;
2426
use function strtolower;
2527
use function strtoupper;
@@ -212,9 +214,15 @@ private function updateConstantValue(Node\Expr\FuncCall|Node\Const_ $node, strin
212214
return;
213215
}
214216

215-
// @ because access to deprecated constant throws deprecated warning
216-
/** @var scalar|resource|list<scalar>|null $constantValue */
217-
$constantValue = @constant($constantName);
217+
// Error handler to suppress deprecated constant warnings (e.g., E_STRICT in PHP 8.4+)
218+
set_error_handler(static fn (): bool => true);
219+
try {
220+
/** @var scalar|resource|list<scalar>|null $constantValue */
221+
$constantValue = constant($constantName);
222+
} finally {
223+
restore_error_handler();
224+
}
225+
218226
$normalizedConstantValue = is_resource($constantValue)
219227
? $this->builderFactory->funcCall('constant', [$constantName])
220228
/** @phpstan-ignore argument.type */

0 commit comments

Comments
 (0)