Skip to content
Closed
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: 6 additions & 6 deletions ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -3327,7 +3327,7 @@ static void instantiate_reflection_method(INTERNAL_FUNCTION_PARAMETERS, bool is_
zend_object *orig_obj = NULL;
zend_class_entry *ce = NULL;
zend_string *class_name = NULL;
char *method_name;
const char *method_name;
size_t method_name_len;
char *lcname;

Expand Down Expand Up @@ -3370,11 +3370,11 @@ static void instantiate_reflection_method(INTERNAL_FUNCTION_PARAMETERS, bool is_
method_name = ZSTR_VAL(arg2_str);
method_name_len = ZSTR_LEN(arg2_str);
} else {
char *tmp;
const char *tmp;
size_t tmp_len;
char *name = ZSTR_VAL(arg1_str);
const char *name = ZSTR_VAL(arg1_str);

if ((tmp = strstr(name, "::")) == NULL) {
if ((tmp = zend_memnstr(name, "::", 2, name + ZSTR_LEN(arg1_str))) == NULL) {
zend_argument_error(reflection_exception_ptr, 1, "must be a valid method name");
RETURN_THROWS();
}
Expand Down Expand Up @@ -4747,7 +4747,7 @@ ZEND_METHOD(ReflectionClass, getProperty)
zend_class_entry *ce, *ce2;
zend_property_info *property_info;
zend_string *name, *classname;
char *tmp, *str_name;
const char *tmp, *str_name;
size_t classname_len, str_name_len;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name) == FAILURE) {
Expand All @@ -4769,7 +4769,7 @@ ZEND_METHOD(ReflectionClass, getProperty)
}
}
str_name = ZSTR_VAL(name);
if ((tmp = strstr(ZSTR_VAL(name), "::")) != NULL) {
if ((tmp = zend_memnstr(ZSTR_VAL(name), "::", 2, ZSTR_VAL(name) + ZSTR_LEN(name))) != NULL) {
classname_len = tmp - ZSTR_VAL(name);
classname = zend_string_init(ZSTR_VAL(name), classname_len, 0);
str_name_len = ZSTR_LEN(name) - (classname_len + 2);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
ReflectionClass::getProperty() with a qualified anonymous class name
--FILE--
<?php

$obj = new class {
public $p = 42;
};

$reflector = new ReflectionClass($obj);
$name = $reflector->getName();
var_dump(str_contains($name, "\0"));

$p = $reflector->getProperty($name . '::p');
var_dump($p->getName(), $p->getValue($obj));

?>
--EXPECT--
bool(true)
string(1) "p"
int(42)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
ReflectionMethod::createFromMethodName() with an anonymous class name
--FILE--
<?php

$obj = new class {
public function m() { return 42; }
};

$name = (new ReflectionClass($obj))->getName();
var_dump(str_contains($name, "\0"));

$m = ReflectionMethod::createFromMethodName($name . '::m');
var_dump($m->getName(), $m->invoke($obj));

?>
--EXPECT--
bool(true)
string(1) "m"
int(42)
Loading