Skip to content

Fatal error in Debian based PHP 8.4.0 RC images #1545

Closed
@Butt4cak3

Description

@Butt4cak3

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions