Author: Tim Düsterhus (TimWolla)
Date: 2025-05-09T13:33:58+02:00
Commit: https://github.com/php/php-src/commit/73c4e9f0b294ec368acd6bc4d4454afa22833902
Raw diff: https://github.com/php/php-src/commit/73c4e9f0b294ec368acd6bc4d4454afa22833902.diff
Merge branch 'PHP-8.4'
* PHP-8.4:
gen_stub: Fix ce_flags
generation for compatibility mode (#18507)
Changed paths:
M build/gen_stub.php
M ext/zend_test/test.c
M ext/zend_test/test.stub.php
M ext/zend_test/test_arginfo.h
Diff:
diff --git a/build/gen_stub.php b/build/gen_stub.php
index 1d2fa79a0666..5e06a53172e0 100755
--- a/build/gen_stub.php
+++ b/build/gen_stub.php
@@ -3481,17 +3481,13 @@ public function getRegistration(array $allConstInfos): string
$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 @@ public function getRegistration(array $allConstInfos): string
$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);
+
}
}
diff --git a/ext/zend_test/test.c b/ext/zend_test/test.c
index 403217e92613..e55e79f9307b 100644
--- a/ext/zend_test/test.c
+++ b/ext/zend_test/test.c
@@ -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();
diff --git a/ext/zend_test/test.stub.php b/ext/zend_test/test.stub.php
index d75e160db978..9923da6dceea 100644
--- a/ext/zend_test/test.stub.php
+++ b/ext/zend_test/test.stub.php
@@ -86,6 +86,13 @@ class _ZendTestChildClass extends _ZendTestClass
public function returnsThrowable(): Exception {}
}
+ /**
+ * @not-serializable
+ */
+ final class ZendTestGenStubFlagCompatibilityTest {
+
+ }
+
class ZendAttributeTest {
/** @var int */
#[ZendTestRepeatableAttribute]
diff --git a/ext/zend_test/test_arginfo.h b/ext/zend_test/test_arginfo.h
index cb39e871a466..d0d12eb66bab 100644
--- a/ext/zend_test/test_arginfo.h
+++ b/ext/zend_test/test_arginfo.h
@@ -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;