Skip to content

Commit afd0444

Browse files
Avoid error with constant $
1 parent 74b909a commit afd0444

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

src/Reflection/BetterReflection/BetterReflectionProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,8 @@ public function resolveConstantName(Node\Name $nameNode, ?NamespaceAnswerer $nam
434434
return true;
435435
} catch (IdentifierNotFound) {
436436
// pass
437+
} catch (InvalidIdentifierName) {
438+
// pass
437439
} catch (UnableToCompileNode) {
438440
// pass
439441
}

tests/PHPStan/Analyser/AnalyserIntegrationTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,6 +1493,12 @@ public function testBug12979(): void
14931493
$this->assertNoErrors($errors);
14941494
}
14951495

1496+
public function testBug12095(): void
1497+
{
1498+
$errors = $this->runAnalyse(__DIR__ . '/data/bug-12095.php');
1499+
$this->assertNoErrors($errors);
1500+
}
1501+
14961502
/**
14971503
* @param string[]|null $allAnalysedFiles
14981504
* @return Error[]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug12095;
4+
5+
class HelloWorld
6+
{
7+
public const XXX = '$';
8+
9+
public function sayHello(): void
10+
{
11+
if(defined(self::XXX)) {
12+
die(0);
13+
}
14+
}
15+
}

0 commit comments

Comments
 (0)