Skip to content

Commit 4a8028c

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: Parse qualified reflection names with a length-aware search
2 parents fc6b78e + 3a9d86a commit 4a8028c

3 files changed

Lines changed: 47 additions & 6 deletions

File tree

ext/reflection/php_reflection.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3318,7 +3318,7 @@ static void instantiate_reflection_method(INTERNAL_FUNCTION_PARAMETERS, bool is_
33183318
zend_object *orig_obj = NULL;
33193319
zend_class_entry *ce = NULL;
33203320
zend_string *class_name = NULL;
3321-
char *method_name;
3321+
const char *method_name;
33223322
size_t method_name_len;
33233323
char *lcname;
33243324

@@ -3361,11 +3361,11 @@ static void instantiate_reflection_method(INTERNAL_FUNCTION_PARAMETERS, bool is_
33613361
method_name = ZSTR_VAL(arg2_str);
33623362
method_name_len = ZSTR_LEN(arg2_str);
33633363
} else {
3364-
char *tmp;
3364+
const char *tmp;
33653365
size_t tmp_len;
3366-
char *name = ZSTR_VAL(arg1_str);
3366+
const char *name = ZSTR_VAL(arg1_str);
33673367

3368-
if ((tmp = strstr(name, "::")) == NULL) {
3368+
if ((tmp = zend_memnstr(name, "::", 2, name + ZSTR_LEN(arg1_str))) == NULL) {
33693369
zend_argument_error(reflection_exception_ptr, 1, "must be a valid method name");
33703370
RETURN_THROWS();
33713371
}
@@ -4684,7 +4684,7 @@ ZEND_METHOD(ReflectionClass, getProperty)
46844684
zend_class_entry *ce, *ce2;
46854685
zend_property_info *property_info;
46864686
zend_string *name, *classname;
4687-
char *tmp, *str_name;
4687+
const char *tmp, *str_name;
46884688
size_t classname_len, str_name_len;
46894689

46904690
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name) == FAILURE) {
@@ -4706,7 +4706,7 @@ ZEND_METHOD(ReflectionClass, getProperty)
47064706
}
47074707
}
47084708
str_name = ZSTR_VAL(name);
4709-
if ((tmp = strstr(ZSTR_VAL(name), "::")) != NULL) {
4709+
if ((tmp = zend_memnstr(ZSTR_VAL(name), "::", 2, ZSTR_VAL(name) + ZSTR_LEN(name))) != NULL) {
47104710
classname_len = tmp - ZSTR_VAL(name);
47114711
classname = zend_string_init(ZSTR_VAL(name), classname_len, 0);
47124712
str_name_len = ZSTR_LEN(name) - (classname_len + 2);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
ReflectionClass::getProperty() with a qualified anonymous class name
3+
--FILE--
4+
<?php
5+
6+
$obj = new class {
7+
public $p = 42;
8+
};
9+
10+
$reflector = new ReflectionClass($obj);
11+
$name = $reflector->getName();
12+
var_dump(str_contains($name, "\0"));
13+
14+
$p = $reflector->getProperty($name . '::p');
15+
var_dump($p->getName(), $p->getValue($obj));
16+
17+
?>
18+
--EXPECT--
19+
bool(true)
20+
string(1) "p"
21+
int(42)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
ReflectionMethod::createFromMethodName() with an anonymous class name
3+
--FILE--
4+
<?php
5+
6+
$obj = new class {
7+
public function m() { return 42; }
8+
};
9+
10+
$name = (new ReflectionClass($obj))->getName();
11+
var_dump(str_contains($name, "\0"));
12+
13+
$m = ReflectionMethod::createFromMethodName($name . '::m');
14+
var_dump($m->getName(), $m->invoke($obj));
15+
16+
?>
17+
--EXPECT--
18+
bool(true)
19+
string(1) "m"
20+
int(42)

0 commit comments

Comments
 (0)