Skip to content

Fix registration of internal readonly child classes #15459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -3488,9 +3488,16 @@ static zend_class_entry *do_register_internal_class(zend_class_entry *orig_class
*/
ZEND_API zend_class_entry *zend_register_internal_class_ex(zend_class_entry *class_entry, zend_class_entry *parent_ce) /* {{{ */
{
zend_class_entry *register_class;
return zend_register_internal_class_with_flags(class_entry, parent_ce, 0);
}
/* }}} */

register_class = zend_register_internal_class(class_entry);
ZEND_API zend_class_entry *zend_register_internal_class_with_flags(
zend_class_entry *class_entry,
zend_class_entry *parent_ce,
uint32_t ce_flags
) {
zend_class_entry *register_class = do_register_internal_class(class_entry, ce_flags);

if (parent_ce) {
zend_do_inheritance(register_class, parent_ce);
Expand All @@ -3499,7 +3506,6 @@ ZEND_API zend_class_entry *zend_register_internal_class_ex(zend_class_entry *cla

return register_class;
}
/* }}} */

ZEND_API void zend_class_implements(zend_class_entry *class_entry, int num_interfaces, ...) /* {{{ */
{
Expand Down
1 change: 1 addition & 0 deletions Zend/zend_API.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ ZEND_API void zend_add_magic_method(zend_class_entry *ce, zend_function *fptr, z

ZEND_API zend_class_entry *zend_register_internal_class(zend_class_entry *class_entry);
ZEND_API zend_class_entry *zend_register_internal_class_ex(zend_class_entry *class_entry, zend_class_entry *parent_ce);
ZEND_API zend_class_entry *zend_register_internal_class_with_flags(zend_class_entry *class_entry, zend_class_entry *parent_ce, uint32_t flags);
ZEND_API zend_class_entry *zend_register_internal_interface(zend_class_entry *orig_class_entry);
ZEND_API void zend_class_implements(zend_class_entry *class_entry, int num_interfaces, ...);

Expand Down
21 changes: 7 additions & 14 deletions Zend/zend_attributes_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Zend/zend_builtin_functions_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Zend/zend_closures_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions Zend/zend_exceptions_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions Zend/zend_fibers_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Zend/zend_generators_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Zend/zend_interfaces_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions Zend/zend_weakrefs_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 25 additions & 4 deletions build/gen_stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -3274,11 +3274,18 @@ public function getRegistration(array $allConstInfos): string
$code .= "static zend_class_entry *register_class_$escapedName(" . (empty($params) ? "void" : implode(", ", $params)) . ")\n";

$code .= "{\n";

$flagCodes = generateVersionDependentFlagCode("%s", $this->getFlagsByPhpVersion(), $this->phpVersionIdMinimumCompatibility);
$flags = implode("", $flagCodes);

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, class_{$escapedName}_methods);\n";
if ($flags !== "") {
$code .= "\tclass_entry->ce_flags |= $flags\n";
}
} else {
$code .= "\tzend_class_entry ce, *class_entry;\n\n";
if (count($this->name->getParts()) > 1) {
Expand All @@ -3291,15 +3298,29 @@ public function getRegistration(array $allConstInfos): string
}

if ($this->type === "class" || $this->type === "trait") {
$code .= "\tclass_entry = zend_register_internal_class_ex(&ce, " . (isset($this->extends[0]) ? "class_entry_" . str_replace("\\", "_", $this->extends[0]->toString()) : "NULL") . ");\n";
if (!$php84MinimumCompatibility) {
$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";

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 .= "#endif\n";
}
} else {
$code .= "\tclass_entry = zend_register_internal_interface(&ce);\n";
if ($flags !== "") {
$code .= "\tclass_entry->ce_flags |= $flags\n";
}
}
}

$flagCodes = generateVersionDependentFlagCode("\tclass_entry->ce_flags |= %s;\n", $this->getFlagsByPhpVersion(), $this->phpVersionIdMinimumCompatibility);
$code .= implode("", $flagCodes);

if ($this->exposedDocComment) {
if (!$php84MinimumCompatibility) {
$code .= "#if (PHP_VERSION_ID >= " . PHP_84_VERSION_ID . ")\n";
Expand Down
Loading
Loading