|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2020-05-22 10:10 UTC] bwoebi@php.net
-Status: Open
+Status: Not a bug
[2020-05-22 10:10 UTC] bwoebi@php.net
[2020-05-22 10:18 UTC] jiri dot fajman at designeo dot cz
[2020-05-22 10:22 UTC] nikic@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 01:00:01 2025 UTC |
Description: ------------ PHP 7.4.6 Following code throws "Typed property A::$x must not be accessed before initialization". Expected behavior: Method getX() returns null. I cannot imagine any single usecase for this behavior and I consider it a serious bug leading back to PHP 7.0 hacks for nullable types in method signature. Note: Omitting getter method is not acceptable since accessing non existing attribute does not throw error. Test script: --------------- <?php class A { private ?string $x; /** * @return string|null */ public function getX(): ?string { return $this->x; } /** * @param string|null $x */ public function setX(?string $x): void { $this->x = $x; } } $a = new A(); var_dump($a->getX()); Expected result: ---------------- Expected result is that var_dump prints null, not crash with fatal error Actual result: -------------- Fatal error: Typed property A::$x must not be accessed before initialization