Skip to content

Simplify php_reflection.c, class name cannot start with backslash #10536

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
Feb 11, 2023
Merged
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
24 changes: 12 additions & 12 deletions ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -3496,7 +3496,7 @@ ZEND_METHOD(ReflectionFunctionAbstract, inNamespace)

zend_string *name = fptr->common.function_name;
const char *backslash = zend_memrchr(ZSTR_VAL(name), '\\', ZSTR_LEN(name));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the best/fastest function to detect if one char is present?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zend_memrchr likely already is the fastest way.

RETURN_BOOL(backslash && backslash > ZSTR_VAL(name));
RETURN_BOOL(backslash);
}
/* }}} */

Expand All @@ -3514,7 +3514,7 @@ ZEND_METHOD(ReflectionFunctionAbstract, getNamespaceName)

zend_string *name = fptr->common.function_name;
const char *backslash = zend_memrchr(ZSTR_VAL(name), '\\', ZSTR_LEN(name));
if (backslash && backslash > ZSTR_VAL(name)) {
if (backslash) {
RETURN_STRINGL(ZSTR_VAL(name), backslash - ZSTR_VAL(name));
}
RETURN_EMPTY_STRING();
Expand All @@ -3535,7 +3535,7 @@ ZEND_METHOD(ReflectionFunctionAbstract, getShortName)

zend_string *name = fptr->common.function_name;
const char *backslash = zend_memrchr(ZSTR_VAL(name), '\\', ZSTR_LEN(name));
if (backslash && backslash > ZSTR_VAL(name)) {
if (backslash) {
RETURN_STRINGL(backslash + 1, ZSTR_LEN(name) - (backslash - ZSTR_VAL(name) + 1));
}
RETURN_STR_COPY(name);
Expand Down Expand Up @@ -5363,7 +5363,7 @@ ZEND_METHOD(ReflectionClass, inNamespace)

zend_string *name = ce->name;
const char *backslash = zend_memrchr(ZSTR_VAL(name), '\\', ZSTR_LEN(name));
RETURN_BOOL(backslash && backslash > ZSTR_VAL(name));
RETURN_BOOL(backslash);
}
/* }}} */

Expand All @@ -5381,7 +5381,7 @@ ZEND_METHOD(ReflectionClass, getNamespaceName)

zend_string *name = ce->name;
const char *backslash = zend_memrchr(ZSTR_VAL(name), '\\', ZSTR_LEN(name));
if (backslash && backslash > ZSTR_VAL(name)) {
if (backslash) {
RETURN_STRINGL(ZSTR_VAL(name), backslash - ZSTR_VAL(name));
}
RETURN_EMPTY_STRING();
Expand All @@ -5402,7 +5402,7 @@ ZEND_METHOD(ReflectionClass, getShortName)

zend_string *name = ce->name;
const char *backslash = zend_memrchr(ZSTR_VAL(name), '\\', ZSTR_LEN(name));
if (backslash && backslash > ZSTR_VAL(name)) {
if (backslash) {
RETURN_STRINGL(backslash + 1, ZSTR_LEN(name) - (backslash - ZSTR_VAL(name) + 1));
}
RETURN_STR_COPY(name);
Expand Down Expand Up @@ -5667,7 +5667,7 @@ ZEND_METHOD(ReflectionProperty, setValue)
}
/* }}} */

/* {{{ Returns this property's value */
/* {{{ Returns true if property was initialized */
ZEND_METHOD(ReflectionProperty, isInitialized)
{
reflection_object *intern;
Expand Down Expand Up @@ -6499,7 +6499,7 @@ ZEND_METHOD(ReflectionAttribute, __toString)
}
/* }}} */

/* {{{ * Returns the name of the attribute */
/* {{{ Returns the name of the attribute */
ZEND_METHOD(ReflectionAttribute, getName)
{
reflection_object *intern;
Expand All @@ -6514,7 +6514,7 @@ ZEND_METHOD(ReflectionAttribute, getName)
}
/* }}} */

/* {{{ * Returns the target of the attribute */
/* {{{ Returns the target of the attribute */
ZEND_METHOD(ReflectionAttribute, getTarget)
{
reflection_object *intern;
Expand All @@ -6529,7 +6529,7 @@ ZEND_METHOD(ReflectionAttribute, getTarget)
}
/* }}} */

/* {{{ * Returns true if the attribute is repeated */
/* {{{ Returns true if the attribute is repeated */
ZEND_METHOD(ReflectionAttribute, isRepeated)
{
reflection_object *intern;
Expand All @@ -6544,7 +6544,7 @@ ZEND_METHOD(ReflectionAttribute, isRepeated)
}
/* }}} */

/* {{{ * Returns the arguments passed to the attribute */
/* {{{ Returns the arguments passed to the attribute */
ZEND_METHOD(ReflectionAttribute, getArguments)
{
reflection_object *intern;
Expand Down Expand Up @@ -6661,7 +6661,7 @@ static void attribute_ctor_cleanup(
}
/* }}} */

/* {{{ * Returns the attribute as an object */
/* {{{ Returns the attribute as an object */
ZEND_METHOD(ReflectionAttribute, newInstance)
{
reflection_object *intern;
Expand Down