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
5 changes: 3 additions & 2 deletions ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, const
}
smart_str_append_printf(str, "class ");
}
smart_str_append_printf(str, "%s", ZSTR_VAL(ce->name));
smart_str_append(str, ce->name);
if (ce->parent) {
smart_str_append_printf(str, " extends %s", ZSTR_VAL(ce->parent->name));
}
Expand Down Expand Up @@ -904,7 +904,8 @@ static void _function_string(smart_str *str, zend_function *fptr, zend_class_ent
if (fptr->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE) {
smart_str_appendc(str, '&');
}
smart_str_append_printf(str, "%s ] {\n", ZSTR_VAL(fptr->common.function_name));
smart_str_append(str, fptr->common.function_name);
smart_str_appends(str, " ] {\n");
/* The information where a function is declared is only available for user classes */
if (fptr->type == ZEND_USER_FUNCTION) {
smart_str_append_printf(str, "%s @@ %s %d - %d\n", indent,
Expand Down
32 changes: 32 additions & 0 deletions ext/reflection/tests/gh22681/ReflectionClass_name.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
--TEST--
GH-22681: null bytes in name truncate ReflectionClass::__toString()
--FILE--
<?php

$obj = new class {};

$r = new ReflectionClass($obj);
echo $r;
var_dump( $r->getName() );

?>
--EXPECTF--
Class [ <user> class class@anonymous%0%s ] {
@@ %s %d-%d

- Constants [0] {
}

- Static properties [0] {
}

- Static methods [0] {
}

- Properties [0] {
}

- Methods [0] {
}
}
string(%d) "class@anonymous%0%s"
21 changes: 21 additions & 0 deletions ext/reflection/tests/gh22681/ReflectionFunctionAbstract_name.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
GH-22681: null bytes in name truncate ReflectionFunction::__toString()
--FILE--
<?php

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

$r = new ReflectionFunction($obj->make());
echo $r;
var_dump( $r->getName() );

?>
--EXPECTF--
Closure [ <user> public method {closure:class@anonymous%0%s::make():%d} ] {
@@ %s %d - %d
}
string(%d) "{closure:class@anonymous%0%s::make():%d}"
Loading