Description
Summary
The Debian based Docker images for PHP 8.4.0 versions (at least RC2 and RC3) throw a fatal error when running the code snippet below.
Test code
<?php
class Foo {
public string $bar {
set => $value;
}
}
$reflector = new ReflectionClass(Foo::class);
$foo = $reflector->newLazyGhost(function ($ghost) {
$ghost->bar = 'bar';
});
echo $foo->bar;
Output
Fatal error: Uncaught Error: Typed property Foo::$bar must not be accessed before initialization in /workspace/test.php:15
Stack trace:
#0 {main}
thrown in /workspace/test.php on line 15
Expected output
bar
Code explanation
Foo
is a class with a property $bar
. $bar
has a set-hook, but specifically no get-hook. When you create a new lazy ghost of Foo
and try to access its $bar
property, PHP throws an error instead of triggering the lazy initialization.
Narrowing down the issue
The reason why I report this here and not on php-src itself is that I only ran into this issue with the Debian based Docker images. I specifically tested with php:8.4.0RC2-cli
and php:8.4.0RC3-cli
. The error does not occur with php:8.4RC3-cli-alpine
. I also tested the same code outside of Docker with a PHP that I compiled from source without issue.
By messing around with the Dockerfile, I found out that the error only occurs when -O2 is present in the CFLAGS. If you remove -O2
from line 57 and rebuild the image, the code runs without errors.