Skip to content

Commit 4d6d4f3

Browse files
committed
Resolve sefl+parent
1 parent 3e39b50 commit 4d6d4f3

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

ext/reflection/php_reflection.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2799,6 +2799,7 @@ ZEND_METHOD(reflection_type, __toString)
27992799
{
28002800
reflection_object *intern;
28012801
type_reference *param;
2802+
zend_string *class_name;
28022803

28032804
if (zend_parse_parameters_none() == FAILURE) {
28042805
return;
@@ -2810,9 +2811,24 @@ ZEND_METHOD(reflection_type, __toString)
28102811
case IS_CALLABLE: RETURN_STRINGL("callable", sizeof("callable") - 1);
28112812
case IS_OBJECT:
28122813
if (param->fptr->type == ZEND_INTERNAL_FUNCTION) {
2813-
RETURN_STRING(((zend_internal_arg_info*)param->arg_info)->class_name);
2814+
const char *name = ((zend_internal_arg_info*)param->arg_info)->class_name;
2815+
2816+
class_name = zend_string_init(name, strlen(name), 0);
2817+
} else {
2818+
class_name = zend_string_copy(param->arg_info->class_name);
2819+
}
2820+
2821+
if (param->fptr->common.scope) {
2822+
if (zend_string_equals_literal_ci(class_name, "self")) {
2823+
zend_string_release(class_name);
2824+
class_name = zend_string_copy(param->fptr->common.scope->name);
2825+
} else if (zend_string_equals_literal_ci(class_name, "parent")) {
2826+
zend_string_release(class_name);
2827+
class_name = zend_string_copy(param->fptr->common.scope->parent->name);
2828+
}
28142829
}
2815-
RETURN_STR(zend_string_copy(param->arg_info->class_name));
2830+
2831+
RETURN_STR(class_name);
28162832
case IS_STRING: RETURN_STRINGL("string", sizeof("string") - 1);
28172833
case _IS_BOOL: RETURN_STRINGL("bool", sizeof("bool") - 1);
28182834
case IS_LONG: RETURN_STRINGL("int", sizeof("int") - 1);

ext/reflection/tests/parameters_typehint.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ function bar(): stdClass { return new stdClass; }
88

99
class c extends stdClass {
1010
function bar(): int { return 1; }
11-
function factory(): self { return new c; }
12-
function pfactory(): parent { return new stdClass; }
11+
function factory(): sElf { return new c; }
12+
function pfactory(): pArent { return new stdClass; }
1313
}
1414

1515
echo "*** function foo\n";
@@ -127,9 +127,9 @@ string(3) "int"
127127
bool(true)
128128
bool(false)
129129
bool(true)
130-
string(4) "self"
130+
string(1) "c"
131131
** Function/method return type 4
132132
bool(true)
133133
bool(false)
134134
bool(true)
135-
string(6) "parent"
135+
string(8) "stdClass"

0 commit comments

Comments
 (0)