Bug #79155 [Asn->Csd]: Property nullability lost when using multiple property definition

From: Date: Thu, 23 Jan 2020 11:56:30 +0000
Subject: Bug #79155 [Asn->Csd]: Property nullability lost when using multiple property definition
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-225061@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 Updated by: nikic@php.net Reported by: ondrej at mirtes dot cz Summary: Property nullability lost when using multiple property definition -Status: Assigned +Status: Closed Type: Bug Package: Reflection related PHP Version: 7.4.1 Assigned To: nikic Block user comment: N Private report: N New Comment: Automatic comment on behalf of nikita.ppv@gmail.com Revision: http://git.php.net/?p=php-src.git;a=commit;h=2eb33818b60f0e089833937605f07fe2dc0a3237 Log: Fixed bug #79155 Previous Comments: ------------------------------------------------------------------------ [2020-01-23 10:26:38] a at b dot c dot de 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. ------------------------------------------------------------------------ [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 (#225061) next »