|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2020-01-22 13:33 UTC] ondrej at mirtes dot cz
Description: ------------ When I define multiple properties within a single statement and a native typehint, ReflectionType reports wrong allowsNull(): private ?DateTimeImmutable $startDate, $endDate; Reproduction: https://3v4l.org/hITTk Related PHPStan issue: https://github.com/phpstan/phpstan/issues/2886 Test script: --------------- <?php declare(strict_types=1); final class CreateStatementRequest { private ?DateTimeImmutable $startDate, $endDate; } $ref = new \ReflectionClass(CreateStatementRequest::class); foreach ($ref->getProperties() as $refProperty) { var_dump($refProperty->getName()); $refType = $refProperty->getType(); var_dump($refType->getName()); var_dump($refType->allowsNull()); var_dump('---'); } Expected result: ---------------- string(9) "startDate" string(17) "DateTimeImmutable" bool(true) string(3) "---" string(7) "endDate" string(17) "DateTimeImmutable" bool(true) string(3) "---" Actual result: -------------- string(9) "startDate" string(17) "DateTimeImmutable" bool(true) string(3) "---" string(7) "endDate" string(17) "DateTimeImmutable" bool(false) string(3) "---" PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 07:00:01 2025 UTC |
Not specifically a reflection issue: the ReflectionClass is accurately reflecting the state of affairs: <?php class foo { public ?string $a, $b; } $t = new foo; $t->a = "start"; $t->b = "end"; echo $t->a, ' ', $t->b, "\n"; echo "Nulling a:\n"; $t->a = null; echo "Nulling b:\n"; $t->b = null; ?> In the above code, property 'a' is nullable, but property 'b' is not. Which seems wrong.