Merge branch 'PHP-8.4'

* PHP-8.4:
  gen_stub: Fix `ce_flags` generation for compatibility mode (#18507)
This commit is contained in:
Tim Düsterhus 2025-05-09 13:33:58 +02:00
commit 73c4e9f0b2
No known key found for this signature in database
4 changed files with 41 additions and 13 deletions

View file

@ -3481,17 +3481,13 @@ class ClassInfo {
$code .= "{\n";
$flags = generateVersionDependentFlagCode("%s", $this->getFlagsByPhpVersion(), $this->phpVersionIdMinimumCompatibility);
$classMethods = ($this->funcInfos === []) ? 'NULL' : "class_{$escapedName}_methods";
if ($this->type === "enum") {
$name = addslashes((string) $this->name);
$backingType = $this->enumBackingType
? $this->enumBackingType->toTypeCode() : "IS_UNDEF";
$code .= "\tzend_class_entry *class_entry = zend_register_internal_enum(\"$name\", $backingType, $classMethods);\n";
if ($flags !== "") {
$code .= "\tclass_entry->ce_flags |= $flags\n";
}
$code .= generateVersionDependentFlagCode("\tclass_entry->ce_flags = %s;\n", $this->getFlagsByPhpVersion(), $this->phpVersionIdMinimumCompatibility);
} else {
$code .= "\tzend_class_entry ce, *class_entry;\n\n";
if (count($this->name->getParts()) > 1) {
@ -3508,22 +3504,25 @@ class ClassInfo {
$code .= "#if (PHP_VERSION_ID >= " . PHP_84_VERSION_ID . ")\n";
}
$code .= "\tclass_entry = zend_register_internal_class_with_flags(&ce, " . (isset($this->extends[0]) ? "class_entry_" . str_replace("\\", "_", $this->extends[0]->toString()) : "NULL") . ", " . ($flags ?: 0) . ");\n";
$template = "\tclass_entry = zend_register_internal_class_with_flags(&ce, " . (isset($this->extends[0]) ? "class_entry_" . str_replace("\\", "_", $this->extends[0]->toString()) : "NULL") . ", %s);\n";
$entries = generateVersionDependentFlagCode($template, $this->getFlagsByPhpVersion(), $this->phpVersionIdMinimumCompatibility ? max($this->phpVersionIdMinimumCompatibility, PHP_84_VERSION_ID) : null);
if ($entries !== '') {
$code .= $entries;
} else {
$code .= sprintf($template, "0");
}
if (!$php84MinimumCompatibility) {
$code .= "#else\n";
$code .= "\tclass_entry = zend_register_internal_class_ex(&ce, " . (isset($this->extends[0]) ? "class_entry_" . str_replace("\\", "_", $this->extends[0]->toString()) : "NULL") . ");\n";
if ($flags !== "") {
$code .= "\tclass_entry->ce_flags |= $flags;\n";
}
$code .= generateVersionDependentFlagCode("\tclass_entry->ce_flags |= %s;\n", $this->getFlagsByPhpVersion(), $this->phpVersionIdMinimumCompatibility);
$code .= "#endif\n";
}
} else {
$code .= "\tclass_entry = zend_register_internal_interface(&ce);\n";
if ($flags !== "") {
$code .= "\tclass_entry->ce_flags |= $flags\n";
}
$code .= generateVersionDependentFlagCode("\tclass_entry->ce_flags |= %s;\n", $this->getFlagsByPhpVersion(), $this->phpVersionIdMinimumCompatibility);
}
}

View file

@ -49,6 +49,7 @@ ZEND_DECLARE_MODULE_GLOBALS(zend_test)
static zend_class_entry *zend_test_interface;
static zend_class_entry *zend_test_class;
static zend_class_entry *zend_test_child_class;
static zend_class_entry *zend_test_gen_stub_flag_compatibility_test;
static zend_class_entry *zend_attribute_test_class;
static zend_class_entry *zend_test_trait;
static zend_class_entry *zend_test_attribute;
@ -1293,6 +1294,8 @@ PHP_MINIT_FUNCTION(zend_test)
memcpy(&zend_test_class_handlers, &std_object_handlers, sizeof(zend_object_handlers));
zend_test_class_handlers.get_method = zend_test_class_method_get;
zend_test_gen_stub_flag_compatibility_test = register_class_ZendTestGenStubFlagCompatibilityTest();
zend_attribute_test_class = register_class_ZendAttributeTest();
zend_test_trait = register_class__ZendTestTrait();

View file

@ -86,6 +86,13 @@ namespace {
public function returnsThrowable(): Exception {}
}
/**
* @not-serializable
*/
final class ZendTestGenStubFlagCompatibilityTest {
}
class ZendAttributeTest {
/** @var int */
#[ZendTestRepeatableAttribute]

View file

@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 8022d3e8b34d0ebd71f1be19eeb720947bea67ed */
* Stub hash: 1fd4c80ed74efcc50698748b2afc89391ed69c72 */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_test_array_return, 0, 0, IS_ARRAY, 0)
ZEND_END_ARG_INFO()
@ -843,6 +843,25 @@ static zend_class_entry *register_class__ZendTestChildClass(zend_class_entry *cl
return class_entry;
}
static zend_class_entry *register_class_ZendTestGenStubFlagCompatibilityTest(void)
{
zend_class_entry ce, *class_entry;
INIT_CLASS_ENTRY(ce, "ZendTestGenStubFlagCompatibilityTest", NULL);
#if (PHP_VERSION_ID >= 80400)
class_entry = zend_register_internal_class_with_flags(&ce, NULL, ZEND_ACC_FINAL|ZEND_ACC_NOT_SERIALIZABLE);
#else
class_entry = zend_register_internal_class_ex(&ce, NULL);
#if (PHP_VERSION_ID >= 80100)
class_entry->ce_flags |= ZEND_ACC_FINAL|ZEND_ACC_NOT_SERIALIZABLE;
#elif (PHP_VERSION_ID >= 80000)
class_entry->ce_flags |= ZEND_ACC_FINAL;
#endif
#endif
return class_entry;
}
static zend_class_entry *register_class_ZendAttributeTest(void)
{
zend_class_entry ce, *class_entry;