Skip to content

Commit dc0b08e

Browse files
Reflection object constants: show types
Instead of trying to find the matching name
1 parent 023ee9c commit dc0b08e

7 files changed

+10
-25
lines changed

ext/reflection/php_reflection.c

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -683,25 +683,10 @@ static int format_default_value(smart_str *str, zval *value) {
683683
} ZEND_HASH_FOREACH_END();
684684
smart_str_appendc(str, ']');
685685
} else if (Z_TYPE_P(value) == IS_OBJECT) {
686-
// Look through the global constants, GH-15902
687-
zend_constant *constant;
688-
zend_string *name = NULL;
689-
690-
ZEND_HASH_MAP_FOREACH_PTR(EG(zend_constants), constant) {
691-
if (
692-
Z_TYPE(constant->value) == IS_OBJECT &&
693-
Z_OBJ(constant->value) == Z_OBJ_P(value)
694-
) {
695-
// Found the right constant
696-
name = constant->name;
697-
break;
698-
}
699-
} ZEND_HASH_FOREACH_END();
700-
if (name == NULL) {
701-
smart_str_appends(str, "<Unknown object value>");
702-
} else {
703-
smart_str_append(str, name);
704-
}
686+
// Show a consistent output with the type of the object, GH-15902
687+
smart_str_appends(str, "object(");
688+
smart_str_append(str, Z_OBJCE_P(value)->name);
689+
smart_str_appends(str, ")");
705690
} else {
706691
ZEND_ASSERT(Z_TYPE_P(value) == IS_CONSTANT_AST);
707692
zend_string *ast_str = zend_ast_export("", Z_ASTVAL_P(value), "");

ext/reflection/tests/gh15902/ReflectionClass-callable.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ string(%d) "Class [ <user> class C ] {
2727
}
2828

2929
- Properties [1] {
30-
Property [ public stdClass $a = FOO ]
30+
Property [ public stdClass $a = object(stdClass) ]
3131
}
3232

3333
- Methods [0] {

ext/reflection/tests/gh15902/ReflectionClass-class.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ string(%d) "Class [ <user> class C ] {
2828
}
2929

3030
- Properties [1] {
31-
Property [ public stdClass $a = FOO ]
31+
Property [ public stdClass $a = object(stdClass) ]
3232
}
3333

3434
- Methods [0] {

ext/reflection/tests/gh15902/ReflectionClass-dots.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ string(%d) "Class [ <user> class C ] {
3030
}
3131

3232
- Properties [1] {
33-
Property [ public stdClass $a = FOO ]
33+
Property [ public stdClass $a = object(stdClass) ]
3434
}
3535

3636
- Methods [0] {

ext/reflection/tests/gh15902/ReflectionProperty-callable.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ var_dump( (string)$reflector );
1515

1616
?>
1717
--EXPECTF--
18-
string(%d) "Property [ public stdClass $a = FOO ]
18+
string(%d) "Property [ public stdClass $a = object(stdClass) ]
1919
"

ext/reflection/tests/gh15902/ReflectionProperty-class.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ var_dump( (string)$reflector );
1515

1616
?>
1717
--EXPECTF--
18-
string(%d) "Property [ public stdClass $a = FOO ]
18+
string(%d) "Property [ public stdClass $a = object(stdClass) ]
1919
"

ext/reflection/tests/gh15902/ReflectionProperty-dots.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ var_dump( (string)$reflector );
1818

1919
?>
2020
--EXPECTF--
21-
string(%d) "Property [ public stdClass $a = FOO ]
21+
string(%d) "Property [ public stdClass $a = object(stdClass) ]
2222
"

0 commit comments

Comments
 (0)