Skip to content

Commit

Permalink
Reflection object constants: show types
Browse files Browse the repository at this point in the history
Instead of trying to find the matching name
  • Loading branch information
DanielEScherzer committed Oct 9, 2024
1 parent 023ee9c commit dc0b08e
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 25 deletions.
23 changes: 4 additions & 19 deletions ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -683,25 +683,10 @@ static int format_default_value(smart_str *str, zval *value) {
} ZEND_HASH_FOREACH_END();
smart_str_appendc(str, ']');
} else if (Z_TYPE_P(value) == IS_OBJECT) {
// Look through the global constants, GH-15902
zend_constant *constant;
zend_string *name = NULL;

ZEND_HASH_MAP_FOREACH_PTR(EG(zend_constants), constant) {
if (
Z_TYPE(constant->value) == IS_OBJECT &&
Z_OBJ(constant->value) == Z_OBJ_P(value)
) {
// Found the right constant
name = constant->name;
break;
}
} ZEND_HASH_FOREACH_END();
if (name == NULL) {
smart_str_appends(str, "<Unknown object value>");
} else {
smart_str_append(str, name);
}
// Show a consistent output with the type of the object, GH-15902
smart_str_appends(str, "object(");
smart_str_append(str, Z_OBJCE_P(value)->name);
smart_str_appends(str, ")");
} else {
ZEND_ASSERT(Z_TYPE_P(value) == IS_CONSTANT_AST);
zend_string *ast_str = zend_ast_export("", Z_ASTVAL_P(value), "");
Expand Down
2 changes: 1 addition & 1 deletion ext/reflection/tests/gh15902/ReflectionClass-callable.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ string(%d) "Class [ <user> class C ] {
}

- Properties [1] {
Property [ public stdClass $a = FOO ]
Property [ public stdClass $a = object(stdClass) ]
}

- Methods [0] {
Expand Down
2 changes: 1 addition & 1 deletion ext/reflection/tests/gh15902/ReflectionClass-class.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ string(%d) "Class [ <user> class C ] {
}

- Properties [1] {
Property [ public stdClass $a = FOO ]
Property [ public stdClass $a = object(stdClass) ]
}

- Methods [0] {
Expand Down
2 changes: 1 addition & 1 deletion ext/reflection/tests/gh15902/ReflectionClass-dots.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ string(%d) "Class [ <user> class C ] {
}

- Properties [1] {
Property [ public stdClass $a = FOO ]
Property [ public stdClass $a = object(stdClass) ]
}

- Methods [0] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ var_dump( (string)$reflector );

?>
--EXPECTF--
string(%d) "Property [ public stdClass $a = FOO ]
string(%d) "Property [ public stdClass $a = object(stdClass) ]
"
2 changes: 1 addition & 1 deletion ext/reflection/tests/gh15902/ReflectionProperty-class.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ var_dump( (string)$reflector );

?>
--EXPECTF--
string(%d) "Property [ public stdClass $a = FOO ]
string(%d) "Property [ public stdClass $a = object(stdClass) ]
"
2 changes: 1 addition & 1 deletion ext/reflection/tests/gh15902/ReflectionProperty-dots.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ var_dump( (string)$reflector );

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

0 comments on commit dc0b08e

Please sign in to comment.