[php-src] Issue #15694: Property Hooks - reflectionProperty::getInitialized

From: Date: Sun, 01 Sep 2024 17:45:25 +0000
Subject: [php-src] Issue #15694: Property Hooks - reflectionProperty::getInitialized
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-247668@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/15694 Author: bkdotcom ### Description The following code: https://3v4l.org/KXI3l/rfc#vgit.master ```php <?php class PropertyHooks { public ?string $backedGetOnly { get => $this->backedGetOnly; } public ?string $backedSetOnly { set (?string $value) { $this->backedSetOnly = $value; } } public ?string $backedGetAndSet { set (?string $value) { $this->backedGetAndSet = $value; } get => $this->backedGetAndSet; } } $propertyHooks = new PropertyHooks(); $reflectionProperty = new ReflectionProperty($propertyHooks, 'backedGetOnly'); $reflectionProperty->isInitialized($propertyHooks); // returns true - I would expect false // backSetOnly reports false // backedGetAndSet reports true - I would also expect false if ($reflectionProperty->isInitialized($propertyHooks)) { $reflectionProperty->getRawValue($propertyHooks); // Uncaught exception 'Error' with message Typed property PropertyHooks::$backedGetOnly must not be accessed before initialization } else { echo 'not initialized'; } ``` Resulted in this output: ``` Fatal error: Uncaught Error: Typed property PropertyHooks::$backedGetOnly must not be accessed before initialization in /in/KXI3l:33 Stack trace: #0 [internal function]: PropertyHooks->$backedGetOnly::get() #1 /in/KXI3l(33): ReflectionProperty->getRawValue(Object(PropertyHooks)) ``` But I expected this output instead: ``` not initialized ``` ReflectionProperty::isInitialized() seems to be based on whether or not there's a get hook instead of the backing-value? ### PHP Version PHP 8.4 (master - 2024-09-01) ### Operating System OSX & 3v4l

« previous php.bugs (#247668) next »