Skip to content

Const expr FCC crashes under preloading #22782

Description

@arnaud-lb

Description

The following code:

// preload.inc

#[Attribute]
class A {
    function __construct(public mixed $fn) {}
}

#[A(strlen(...))]
class C {
    const CC = strlen(...);

    #[A(strlen(...))]
    function f($arg = strlen(...)) {
        return $arg;
    }
}

const CC = strlen(...);
// preload.php

echo "# Class const\n";
var_dump((C::CC)('hello'));
echo "# Class attr\n";
var_dump((new ReflectionClass(C::class)->getAttributes(A::class)[0]->newInstance()->fn)('hello'));
echo "# Method attr\n";
var_dump((new ReflectionMethod(C::class, 'f')->getAttributes(A::class)[0]->newInstance()->fn)('hello'));
echo "# Method default value\n";
var_dump((new C()->f())('hello'));

When executed with

$ php -d opcache.enable_cli=1 -d opcache.preload=preload.inc preload.php

Resulted in two issues:

  • Preloading evaluates class constants during compilation, but FCCs evaluate to objects, which can't be persisted
  • zend_fcc_ast->fptr is allocated with ZEND_MAP_PTR_NEW during compilation, which results in map ptr collisions later

PHP Version

PHP 8.5

Operating System

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions