Bug #79155 [Com]: Wrong ReflectionType::allowsNull value with multiple property definition

From: Date: Thu, 23 Jan 2020 10:26:38 +0000
Subject: Bug #79155 [Com]: Wrong ReflectionType::allowsNull value with multiple property definition
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-225060@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79155&edit=1 ID: 79155 Comment by: a at b dot c dot de Reported by: ondrej at mirtes dot cz Summary: Wrong ReflectionType::allowsNull value with multiple property definition Status: Open Type: Bug Package: Reflection related PHP Version: 7.4.1 Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2020-01-22 13:33:37] 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) "---" ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=79155&edit=1

« previous php.bugs (#225060) next »