-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
Conversation
@nielsdos @iluuu1994 May I get a review from you? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes seem fine, just 2 remarks/questions about the stub generator
build/gen_stub.php
Outdated
$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") . ", " . (implode("", $flagCodes) ?: 0) . ");\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$code .= "\tclass_entry = zend_register_internal_class_with_flags(&ce, " . (isset($this->extends[0]) ? "class_entry_" . str_replace("\\", "_", $this->extends[0]->toString()) : "NULL") . ", " . (implode("", $flagCodes) ?: 0) . ");\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"; |
build/gen_stub.php
Outdated
$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"; | ||
$code .= "\tclass_entry->ce_flags |= " . implode("", $flagCodes) . "\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can use $flags too.
Also, don't you need to check if $flags !== "" here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I definitely should have checked it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes look correct to me.
Currently, internal classes are registered with the following code:
This has worked well so far, except if
InternalClass
is a readonly class. It is because some inheritance checks are run byzend_register_internal_class_ex
, beforeZEND_ACC_READONLY_CLASS
is added toce_flags
.The issue is fixed by adding a
zend_register_internal_class_with_flags()
zend API function that stubs can use from now on. This function makes sure to add the flags before running any checks. Since the new API is not available in lower PHP versions, gen_stub.php has to keep support for the existing API for PHP 8.4-.The fix is tested in #14461 where I originally found the issue.