Skip to content

Commit d5a4746

Browse files
staabmondrejmirtes
authored andcommitted
NULL and null as a property default value are treated differently when overriding a parent property
1 parent 6c85acc commit d5a4746

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

src/Rules/Properties/DefaultValueTypesAssignedToPropertiesRule.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function processNode(Node $node, Scope $scope): array
3939
$propertyReflection = $classReflection->getNativeProperty($node->getName());
4040
$propertyType = $propertyReflection->getWritableType();
4141
if ($propertyReflection->getNativeType() instanceof MixedType) {
42-
if ($default instanceof Node\Expr\ConstFetch && (string) $default->name === 'null') {
42+
if ($default instanceof Node\Expr\ConstFetch && $default->name->toLowerString() === 'null') {
4343
return [];
4444
}
4545
}

tests/PHPStan/Rules/Properties/DefaultValueTypesAssignedToPropertiesRuleTest.php

+5
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,9 @@ public function testBug7933(): void
6464
$this->analyse([__DIR__ . '/data/bug-7933.php'], []);
6565
}
6666

67+
public function testBug10987(): void
68+
{
69+
$this->analyse([__DIR__ . '/data/bug-10987.php'], []);
70+
}
71+
6772
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Bug10987;
6+
7+
class Base
8+
{
9+
/** @var string */
10+
public $layout;
11+
}
12+
13+
class A extends Base
14+
{
15+
public $layout = null;
16+
}
17+
18+
class B extends Base
19+
{
20+
public $layout = NULL;
21+
}

0 commit comments

Comments
 (0)