Skip to content

Commit e66a63c

Browse files
Fix
1 parent 497c2fd commit e66a63c

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

src/Rules/Properties/AccessPropertiesCheck.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ private function processSingleProperty(Scope $scope, PropertyFetch $node, string
130130
}
131131

132132
$has = $type->hasInstanceProperty($name);
133-
if ($has->maybe()) {
133+
$hasStatic = $type->hasStaticProperty($name);
134+
if ($has->maybe() && !$hasStatic->yes()) {
134135
if ($scope->isUndefinedExpressionAllowed($node)) {
135136
if (!$this->checkDynamicProperties) {
136137
return [];
@@ -202,7 +203,7 @@ private function processSingleProperty(Scope $scope, PropertyFetch $node, string
202203
}
203204
}
204205

205-
if ($type->hasStaticProperty($name)->yes()) {
206+
if ($hasStatic->yes()) {
206207
return [
207208
RuleErrorBuilder::message(sprintf(
208209
'Non-static access to static property %s::$%s.',

tests/PHPStan/Rules/Properties/AccessStaticPropertiesRuleTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,4 +317,26 @@ public function testBug12775(): void
317317
$this->analyse([__DIR__ . '/data/bug-12775.php'], []);
318318
}
319319

320+
public function testBug8668Bis(): void
321+
{
322+
$this->analyse([__DIR__ . '/data/bug-8668-bis.php'], [
323+
[
324+
'Static access to instance property Bug8668Bis\Sample::$sample.',
325+
9,
326+
],
327+
[
328+
'Static access to instance property Bug8668Bis\Sample::$sample.',
329+
10,
330+
],
331+
[
332+
'Static access to instance property Bug8668Bis\Sample2::$sample.',
333+
20,
334+
],
335+
[
336+
'Static access to instance property Bug8668Bis\Sample2::$sample.',
337+
21,
338+
],
339+
]);
340+
}
341+
320342
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Bug8668Bis;
4+
5+
class Sample {
6+
private string $sample = 'abc';
7+
8+
public function test(): void {
9+
echo self::$sample;
10+
echo isset(self::$sample);
11+
12+
echo $this->sample; // ok
13+
}
14+
}
15+
16+
class Sample2 {
17+
private $sample = 'abc';
18+
19+
public function test(): void {
20+
echo self::$sample;
21+
echo isset(self::$sample);
22+
23+
echo $this->sample; // ok
24+
}
25+
}

0 commit comments

Comments
 (0)