Skip to content

Display class constant and property doc comments via reflection #13499

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2024
Merged
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
7 changes: 7 additions & 0 deletions ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,10 @@ static void _class_const_string(smart_str *str, zend_string *name, zend_class_co
const char *final = ZEND_CLASS_CONST_FLAGS(c) & ZEND_ACC_FINAL ? "final " : "";
zend_string *type_str = ZEND_TYPE_IS_SET(c->type) ? zend_type_to_string(c->type) : NULL;
const char *type = type_str ? ZSTR_VAL(type_str) : zend_zval_type_name(&c->value);

if (c->doc_comment) {
smart_str_append_printf(str, "%s%s\n", indent, ZSTR_VAL(c->doc_comment));
}
smart_str_append_printf(str, "%sConstant [ %s%s %s %s ] { ",
indent, final, visibility, type, ZSTR_VAL(name));
if (Z_TYPE(c->value) == IS_ARRAY) {
Expand Down Expand Up @@ -889,6 +893,9 @@ static zval *property_get_default(zend_property_info *prop_info) {
/* {{{ _property_string */
static void _property_string(smart_str *str, zend_property_info *prop, const char *prop_name, char* indent)
{
if (prop && prop->doc_comment) {
smart_str_append_printf(str, "%s%s\n", indent, ZSTR_VAL(prop->doc_comment));
}
smart_str_append_printf(str, "%sProperty [ ", indent);
if (!prop) {
smart_str_append_printf(str, "<dynamic> public $%s", prop_name);
Expand Down
6 changes: 4 additions & 2 deletions ext/reflection/tests/ReflectionClassConstant_basic1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ reflectClassConstant($instance, "BAD_CONST");
Reflecting on class constant TestClass::PUB

__toString():
string(35) "Constant [ public bool PUB ] { 1 }
string(57) "/** My Doc comment */
Constant [ public bool PUB ] { 1 }
"
getName():
string(3) "PUB"
Expand Down Expand Up @@ -89,7 +90,8 @@ bool
Reflecting on class constant TestClass::PROT

__toString():
string(38) "Constant [ protected int PROT ] { 4 }
string(65) "/** Another doc comment */
Constant [ protected int PROT ] { 4 }
"
getName():
string(4) "PROT"
Expand Down
1 change: 1 addition & 0 deletions ext/reflection/tests/constructor_promotion.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Class [ <user> class Test ] {
- Properties [3] {
Property [ public $z = NULL ]
Property [ public int $x ]
/** @SomeAnnotation() */
Property [ public string $y ]
}

Expand Down