-
Notifications
You must be signed in to change notification settings - Fork 7.9k
reflection: try to avoid manual string comparison #17726
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
base: master
Are you sure you want to change the base?
Conversation
In `is_closure_invoke()` compare with the well known zend_string `ZEND_STR_MAGIC_INVOKE` rather than the underlying literal value.
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.
There is another one in
php-src/ext/reflection/php_reflection.c
Lines 3247 to 3248 in 459fc9d
if (ce == zend_ce_closure && orig_obj && (method_name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) | |
&& memcmp(lcname, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0 |
Make use of the well known zend_string objects `ZEND_STR_MAGIC_INVOKE` and `ZEND_STR_UNKNOWN_CAPITALIZED`
So I tried to fix the other case you found in reflection, but that one is really complicated, since the source being compared is also a char array, and its not clear how to get a zend_string in the case when the char array was extracted from the broader string of I addressed the builtin functions, but I'll note that using |
I think that one could be:
That would at least hide away the length comparison and the memcmp in a function, making it a little less verbose. |
FWIW: Those are not calls. Those are just macros hiding a field access on the struct. |
There's another use of ZEND_INVOKE_FUNC_NAME in: Line 513 in 0006522
Overall this PR LGTM though. I suggest to retitle it to something like “Compare strings with ZEND_STR_MAGIC_INVOKE rather than ZEND_INVOKE_FUNC_NAME” (or whatever), since you are not just touching reflection here. Feel free to merge when you're happy without another review pass. |
In
is_closure_invoke()
compare with the well known zend_stringZEND_STR_MAGIC_INVOKE
rather than the underlying literal value.