Skip to content

Commit 73c4e9f

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: gen_stub: Fix `ce_flags` generation for compatibility mode (#18507)
2 parents 2b0cb76 + 84f82d0 commit 73c4e9f

File tree

4 files changed

+41
-13
lines changed

4 files changed

+41
-13
lines changed

build/gen_stub.php

+11-12
Original file line numberDiff line numberDiff line change
@@ -3481,17 +3481,13 @@ public function getRegistration(array $allConstInfos): string
34813481

34823482
$code .= "{\n";
34833483

3484-
$flags = generateVersionDependentFlagCode("%s", $this->getFlagsByPhpVersion(), $this->phpVersionIdMinimumCompatibility);
3485-
34863484
$classMethods = ($this->funcInfos === []) ? 'NULL' : "class_{$escapedName}_methods";
34873485
if ($this->type === "enum") {
34883486
$name = addslashes((string) $this->name);
34893487
$backingType = $this->enumBackingType
34903488
? $this->enumBackingType->toTypeCode() : "IS_UNDEF";
34913489
$code .= "\tzend_class_entry *class_entry = zend_register_internal_enum(\"$name\", $backingType, $classMethods);\n";
3492-
if ($flags !== "") {
3493-
$code .= "\tclass_entry->ce_flags |= $flags\n";
3494-
}
3490+
$code .= generateVersionDependentFlagCode("\tclass_entry->ce_flags = %s;\n", $this->getFlagsByPhpVersion(), $this->phpVersionIdMinimumCompatibility);
34953491
} else {
34963492
$code .= "\tzend_class_entry ce, *class_entry;\n\n";
34973493
if (count($this->name->getParts()) > 1) {
@@ -3508,22 +3504,25 @@ public function getRegistration(array $allConstInfos): string
35083504
$code .= "#if (PHP_VERSION_ID >= " . PHP_84_VERSION_ID . ")\n";
35093505
}
35103506

3511-
$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";
3507+
$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";
3508+
$entries = generateVersionDependentFlagCode($template, $this->getFlagsByPhpVersion(), $this->phpVersionIdMinimumCompatibility ? max($this->phpVersionIdMinimumCompatibility, PHP_84_VERSION_ID) : null);
3509+
if ($entries !== '') {
3510+
$code .= $entries;
3511+
} else {
3512+
$code .= sprintf($template, "0");
3513+
}
35123514

35133515
if (!$php84MinimumCompatibility) {
35143516
$code .= "#else\n";
35153517

35163518
$code .= "\tclass_entry = zend_register_internal_class_ex(&ce, " . (isset($this->extends[0]) ? "class_entry_" . str_replace("\\", "_", $this->extends[0]->toString()) : "NULL") . ");\n";
3517-
if ($flags !== "") {
3518-
$code .= "\tclass_entry->ce_flags |= $flags;\n";
3519-
}
3519+
$code .= generateVersionDependentFlagCode("\tclass_entry->ce_flags |= %s;\n", $this->getFlagsByPhpVersion(), $this->phpVersionIdMinimumCompatibility);
35203520
$code .= "#endif\n";
35213521
}
35223522
} else {
35233523
$code .= "\tclass_entry = zend_register_internal_interface(&ce);\n";
3524-
if ($flags !== "") {
3525-
$code .= "\tclass_entry->ce_flags |= $flags\n";
3526-
}
3524+
$code .= generateVersionDependentFlagCode("\tclass_entry->ce_flags |= %s;\n", $this->getFlagsByPhpVersion(), $this->phpVersionIdMinimumCompatibility);
3525+
35273526
}
35283527
}
35293528

ext/zend_test/test.c

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ ZEND_DECLARE_MODULE_GLOBALS(zend_test)
4949
static zend_class_entry *zend_test_interface;
5050
static zend_class_entry *zend_test_class;
5151
static zend_class_entry *zend_test_child_class;
52+
static zend_class_entry *zend_test_gen_stub_flag_compatibility_test;
5253
static zend_class_entry *zend_attribute_test_class;
5354
static zend_class_entry *zend_test_trait;
5455
static zend_class_entry *zend_test_attribute;
@@ -1293,6 +1294,8 @@ PHP_MINIT_FUNCTION(zend_test)
12931294
memcpy(&zend_test_class_handlers, &std_object_handlers, sizeof(zend_object_handlers));
12941295
zend_test_class_handlers.get_method = zend_test_class_method_get;
12951296

1297+
zend_test_gen_stub_flag_compatibility_test = register_class_ZendTestGenStubFlagCompatibilityTest();
1298+
12961299
zend_attribute_test_class = register_class_ZendAttributeTest();
12971300

12981301
zend_test_trait = register_class__ZendTestTrait();

ext/zend_test/test.stub.php

+7
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ class _ZendTestChildClass extends _ZendTestClass
8686
public function returnsThrowable(): Exception {}
8787
}
8888

89+
/**
90+
* @not-serializable
91+
*/
92+
final class ZendTestGenStubFlagCompatibilityTest {
93+
94+
}
95+
8996
class ZendAttributeTest {
9097
/** @var int */
9198
#[ZendTestRepeatableAttribute]

ext/zend_test/test_arginfo.h

+20-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)