Skip to content

Avoid truncation on null bytes in class and function names - #22971

Closed
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/reflection-tostring-nul-names
Closed

Avoid truncation on null bytes in class and function names#22971
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/reflection-tostring-nul-names

Conversation

@iliaal

@iliaal iliaal commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Follow-up to GH-22681. _class_string() and _function_string() still format the class name and the function name with %s, so Reflection*::__toString() cuts both at the first NUL byte. Anonymous class names embed one, directly and also inside the generated name of a closure declared in such a class.

$obj = new class {
    public function make(): Closure { return function () {}; }
};
echo new ReflectionFunction($obj->make());
// Closure [ <user> public method {closure:class@anonymous ] {

master already appends the class name as a zend_string, so only the function name changes once this is merged up.

@iliaal
iliaal requested a review from DanielEScherzer as a code owner July 31, 2026 13:26
@iliaal
iliaal force-pushed the fix/reflection-tostring-nul-names branch from 455a1a0 to ccf2ce7 Compare July 31, 2026 13:27
iliaal added a commit to iliaal/php-src that referenced this pull request Jul 31, 2026
Follow-up to phpGH-22681. _class_string() and _function_string() still
formatted the class name and the function name with %s, so
Reflection*::__toString() cut them at the first NUL. Anonymous class
names embed one, both directly and inside the name of a closure declared
in such a class.

Closes phpGH-22971

$obj = new class {
public function make(): Closure {
return function () { };

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
return function () { };
return function () {};

Follow-up to phpGH-22681. _class_string() and _function_string() still
formatted the class name and the function name with %s, so
Reflection*::__toString() cut them at the first NUL. Anonymous class
names embed one, both directly and inside the name of a closure declared
in such a class.

Closes phpGH-22971
@iliaal
iliaal force-pushed the fix/reflection-tostring-nul-names branch from ccf2ce7 to 5d3d462 Compare July 31, 2026 14:55
@iliaal iliaal closed this in 841fe26 Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants