-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Improve string class constant code generation #9577
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
977190b
to
d3b385f
Compare
@@ -1670,7 +1670,7 @@ public function initializeZval(string $zvalName, iterable $allConstInfos): strin | |||
$code .= "\tZVAL_EMPTY_STRING(&$zvalName);\n"; | |||
} else { | |||
$constValue = $cConstValue ?: '"' . addslashes($this->value) . '"'; | |||
$code .= "\tzend_string *{$zvalName}_str = zend_string_init($constValue, sizeof($constValue) - 1, 1);\n"; | |||
$code .= "\tzend_string *{$zvalName}_str = zend_string_init($constValue, strlen($constValue), 1);\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 .= "\tzend_string *{$zvalName}_str = zend_string_init($constValue, strlen($constValue), 1);\n"; | |
$code .= "\tzend_string *{$zvalName}_str = zend_string_init($constValue, strlen($constValue), true);\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.
@kocsismate why is 1
preferred over true
?
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.
@mvorisek I wouldn't say at all that 1
is preferred, but TBH I don't really care which value is used.
While this seems OK, why not simply use |
Unfortunately, it's not possible to call zend_declare_class_const_string() directly, since it only supports declaring public constants. :( |
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.
Thank you!
Using strlen() will make sure that non-constant values can also be used.
d3b385f
to
45caf1a
Compare
I don't see any problem with using
strlen()
, especially becausezend_declare_class_const_string()
has always been using this function until PHP 8.2. Unfortunately, it's not possible to callzend_declare_class_const_string()
directly, since it only supports declaring public constants.