Files
php-src/ext/reflection/tests/ReflectionMethod_createFromMethodName_anonymous_class.phpt
Ilia Alshanetsky 3a9d86a81b Parse qualified reflection names with a length-aware search
ReflectionMethod::__construct(), ReflectionMethod::createFromMethodName()
and ReflectionClass::getProperty() split "Class::member" with strstr(),
which stops at the first NUL. Anonymous class names embed one, so a name
obtained from ReflectionClass::getName() was rejected. Use zend_memnstr()
over the whole string instead.

Closes GH-22970
2026-07-31 11:56:18 -04:00

21 lines
394 B
PHP

--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)