Skip to content

Commit 0e47e36

Browse files
Avoid error with constant name $
1 parent 7358b7e commit 0e47e36

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

phpstan-baseline.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ parameters:
236236

237237
-
238238
message: "#^Dead catch \\- PHPStan\\\\BetterReflection\\\\Identifier\\\\Exception\\\\InvalidIdentifierName is never thrown in the try block\\.$#"
239-
count: 3
239+
count: 4
240240
path: src/Reflection/BetterReflection/BetterReflectionProvider.php
241241

242242
-

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
@@ -1506,6 +1506,12 @@ public function testBug12979(): void
15061506
$this->assertNoErrors($errors);
15071507
}
15081508

1509+
public function testBug12095(): void
1510+
{
1511+
$errors = $this->runAnalyse(__DIR__ . '/data/bug-12095.php');
1512+
$this->assertNoErrors($errors);
1513+
}
1514+
15091515
/**
15101516
* @param string[]|null $allAnalysedFiles
15111517
* @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)