Skip to content

Commit eded2c3

Browse files
committed
Standalone null with default value null does not make parameter implicitly nullable
1 parent c126d48 commit eded2c3

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

src/Rules/FunctionDefinitionCheck.php

+7
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,13 @@ private function checkImplicitlyNullableType(
710710
return null;
711711
}
712712

713+
if ($type instanceof Identifier && strtolower($type->name) === 'null') {
714+
return null;
715+
}
716+
if ($type instanceof Name && $type->toLowerString() === 'null') {
717+
return null;
718+
}
719+
713720
if ($type instanceof UnionType) {
714721
foreach ($type->types as $innerType) {
715722
if ($innerType instanceof Identifier && strtolower($innerType->name) === 'null') {

tests/PHPStan/Rules/Methods/ExistingClassesInTypehintsRuleTest.php

+8
Original file line numberDiff line numberDiff line change
@@ -548,4 +548,12 @@ public function testDeprecatedImplicitlyNullableParameterType(): void
548548
]);
549549
}
550550

551+
public function testBug12501(): void
552+
{
553+
if (PHP_VERSION_ID < 80400) {
554+
self::markTestSkipped('This test needs PHP 8.4.');
555+
}
556+
$this->analyse([__DIR__ . '/data/bug-12501.php'], []);
557+
}
558+
551559
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php // lint >= 8.4
2+
3+
declare(strict_types = 1);
4+
5+
namespace Bug12501;
6+
7+
final readonly class EmptyObject {
8+
public function __construct(
9+
public null $value1 = null,
10+
) {}
11+
}

0 commit comments

Comments
 (0)