Skip to content

Commit

Permalink
NULL and null as a property default value are treated differently whe…
Browse files Browse the repository at this point in the history
…n overriding a parent property
  • Loading branch information
staabm authored and ondrejmirtes committed May 12, 2024
1 parent 6c85acc commit d5a4746
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function processNode(Node $node, Scope $scope): array
$propertyReflection = $classReflection->getNativeProperty($node->getName());
$propertyType = $propertyReflection->getWritableType();
if ($propertyReflection->getNativeType() instanceof MixedType) {
if ($default instanceof Node\Expr\ConstFetch && (string) $default->name === 'null') {
if ($default instanceof Node\Expr\ConstFetch && $default->name->toLowerString() === 'null') {
return [];
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,9 @@ public function testBug7933(): void
$this->analyse([__DIR__ . '/data/bug-7933.php'], []);
}

public function testBug10987(): void
{
$this->analyse([__DIR__ . '/data/bug-10987.php'], []);
}

}
21 changes: 21 additions & 0 deletions tests/PHPStan/Rules/Properties/data/bug-10987.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Bug10987;

class Base
{
/** @var string */
public $layout;
}

class A extends Base
{
public $layout = null;
}

class B extends Base
{
public $layout = NULL;
}

0 comments on commit d5a4746

Please sign in to comment.