Skip to content

Commit 2b5c527

Browse files
committed
Unify with _const_string
1 parent 51626dd commit 2b5c527

File tree

2 files changed

+40
-25
lines changed

2 files changed

+40
-25
lines changed

ext/reflection/php_reflection.c

+36-21
Original file line numberDiff line numberDiff line change
@@ -539,20 +539,48 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, char
539539
static void _const_string(smart_str *str, char *name, zval *value, char *indent)
540540
{
541541
const char *type = zend_zval_type_name(value);
542+
uint32_t flags = Z_CONSTANT_FLAGS_P(value);
543+
544+
smart_str_appends(str, indent);
545+
smart_str_appends(str, "Constant [ ");
546+
547+
if (flags & (CONST_PERSISTENT|CONST_NO_FILE_CACHE|CONST_DEPRECATED)) {
548+
bool first = true;
549+
smart_str_appends(str, "<");
550+
551+
#define DUMP_CONST_FLAG(flag, output) \
552+
do { \
553+
if (flags & flag) { \
554+
if (!first) smart_str_appends(str, ", "); \
555+
smart_str_appends(str, output); \
556+
first = false; \
557+
} \
558+
} while (0)
559+
DUMP_CONST_FLAG(CONST_PERSISTENT, "persistent");
560+
DUMP_CONST_FLAG(CONST_NO_FILE_CACHE, "no_file_cache");
561+
DUMP_CONST_FLAG(CONST_DEPRECATED, "deprecated");
562+
#undef DUMP_CONST_FLAG
563+
564+
smart_str_appends(str, "> ");
565+
}
566+
567+
smart_str_appends(str, type);
568+
smart_str_appendc(str, ' ');
569+
smart_str_appends(str, name);
570+
smart_str_appends(str, " ] { ");
542571

543572
if (Z_TYPE_P(value) == IS_ARRAY) {
544-
smart_str_append_printf(str, "%s Constant [ %s %s ] { Array }\n",
545-
indent, type, name);
573+
smart_str_appends(str, "Array");
546574
} else if (Z_TYPE_P(value) == IS_STRING) {
547-
smart_str_append_printf(str, "%s Constant [ %s %s ] { %s }\n",
548-
indent, type, name, Z_STRVAL_P(value));
575+
smart_str_appends(str, Z_STRVAL_P(value));
549576
} else {
550577
zend_string *tmp_value_str;
551578
zend_string *value_str = zval_get_tmp_string(value, &tmp_value_str);
552-
smart_str_append_printf(str, "%s Constant [ %s %s ] { %s }\n",
553-
indent, type, name, ZSTR_VAL(value_str));
579+
smart_str_appends(str, ZSTR_VAL(value_str));
554580
zend_tmp_string_release(tmp_value_str);
555581
}
582+
583+
smart_str_appends(str, " }\n");
556584
}
557585
/* }}} */
558586

@@ -1060,7 +1088,7 @@ static void _extension_string(smart_str *str, zend_module_entry *module, char *i
10601088

10611089
ZEND_HASH_MAP_FOREACH_PTR(EG(zend_constants), constant) {
10621090
if (ZEND_CONSTANT_MODULE_NUMBER(constant) == module->module_number) {
1063-
_const_string(&str_constants, ZSTR_VAL(constant->name), &constant->value, indent);
1091+
_const_string(&str_constants, ZSTR_VAL(constant->name), &constant->value, " ");
10641092
num_constants++;
10651093
}
10661094
} ZEND_HASH_FOREACH_END();
@@ -1251,19 +1279,6 @@ static void _zend_extension_string(smart_str *str, zend_extension *extension, ch
12511279
}
12521280
/* }}} */
12531281

1254-
static void _const_decl_string(smart_str *str, zend_constant *const_)
1255-
{
1256-
smart_str_append_printf(str, "Const [ ");
1257-
if (ZEND_CONSTANT_FLAGS(const_) & CONST_DEPRECATED) {
1258-
smart_str_append_printf(str, "<deprecated> ");
1259-
}
1260-
smart_str_append_printf(str, "%s = ", ZSTR_VAL(const_->name));
1261-
if (format_default_value(str, &const_->value) == FAILURE) {
1262-
return;
1263-
}
1264-
smart_str_appends(str, " ]\n");
1265-
}
1266-
12671282
/* {{{ _function_check_flag */
12681283
static void _function_check_flag(INTERNAL_FUNCTION_PARAMETERS, int mask)
12691284
{
@@ -7351,7 +7366,7 @@ ZEND_METHOD(ReflectionConstant, __toString)
73517366
}
73527367

73537368
GET_REFLECTION_OBJECT_PTR(const_);
7354-
_const_decl_string(&str, const_);
7369+
_const_string(&str, ZSTR_VAL(const_->name), &const_->value, "");
73557370
RETURN_STR(smart_str_extract(&str));
73567371
}
73577372

ext/reflection/tests/ReflectionConstant_dump.phpt

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@ object(ReflectionConstant)#1 (1) {
2727
["name"]=>
2828
string(15) "ZEND_CONSTANT_A"
2929
}
30-
Const [ ZEND_CONSTANT_A = 'global' ]
30+
Constant [ <persistent> string ZEND_CONSTANT_A ] { global }
3131
object(ReflectionConstant)#1 (1) {
3232
["name"]=>
3333
string(20) "ZEND_TEST_DEPRECATED"
3434
}
35-
Const [ <deprecated> ZEND_TEST_DEPRECATED = 42 ]
35+
Constant [ <persistent, deprecated> int ZEND_TEST_DEPRECATED ] { 42 }
3636
object(ReflectionConstant)#1 (1) {
3737
["name"]=>
3838
string(8) "RT_CONST"
3939
}
40-
Const [ RT_CONST = 42 ]
40+
Constant [ int RT_CONST ] { 42 }
4141
object(ReflectionConstant)#1 (1) {
4242
["name"]=>
4343
string(8) "CT_CONST"
4444
}
45-
Const [ CT_CONST = ['foo' => 'foo', 'bar' => ['bar']] ]
45+
Constant [ array CT_CONST ] { Array }

0 commit comments

Comments
 (0)