Skip to content

Commit ec751aa

Browse files
committed
Unify with _const_string
1 parent 51626dd commit ec751aa

File tree

3 files changed

+59
-44
lines changed

3 files changed

+59
-44
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 }

sapi/cli/tests/006.phpt

+19-19
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,25 @@ string(%d) "Extension [ <persistent> extension #%d pcre version %s ] {
4343
}
4444

4545
- Constants [19] {
46-
Constant [ int PREG_PATTERN_ORDER ] { 1 }
47-
Constant [ int PREG_SET_ORDER ] { 2 }
48-
Constant [ int PREG_OFFSET_CAPTURE ] { 256 }
49-
Constant [ int PREG_UNMATCHED_AS_NULL ] { 512 }
50-
Constant [ int PREG_SPLIT_NO_EMPTY ] { 1 }
51-
Constant [ int PREG_SPLIT_DELIM_CAPTURE ] { 2 }
52-
Constant [ int PREG_SPLIT_OFFSET_CAPTURE ] { 4 }
53-
Constant [ int PREG_GREP_INVERT ] { 1 }
54-
Constant [ int PREG_NO_ERROR ] { 0 }
55-
Constant [ int PREG_INTERNAL_ERROR ] { 1 }
56-
Constant [ int PREG_BACKTRACK_LIMIT_ERROR ] { 2 }
57-
Constant [ int PREG_RECURSION_LIMIT_ERROR ] { 3 }
58-
Constant [ int PREG_BAD_UTF8_ERROR ] { 4 }
59-
Constant [ int PREG_BAD_UTF8_OFFSET_ERROR ] { 5 }
60-
Constant [ int PREG_JIT_STACKLIMIT_ERROR ] { 6 }
61-
Constant [ string PCRE_VERSION ] { %s }
62-
Constant [ int PCRE_VERSION_MAJOR ] { %d }
63-
Constant [ int PCRE_VERSION_MINOR ] { %d }
64-
Constant [ bool PCRE_JIT_SUPPORT ] { %d }
46+
Constant [ <persistent> int PREG_PATTERN_ORDER ] { 1 }
47+
Constant [ <persistent> int PREG_SET_ORDER ] { 2 }
48+
Constant [ <persistent> int PREG_OFFSET_CAPTURE ] { 256 }
49+
Constant [ <persistent> int PREG_UNMATCHED_AS_NULL ] { 512 }
50+
Constant [ <persistent> int PREG_SPLIT_NO_EMPTY ] { 1 }
51+
Constant [ <persistent> int PREG_SPLIT_DELIM_CAPTURE ] { 2 }
52+
Constant [ <persistent> int PREG_SPLIT_OFFSET_CAPTURE ] { 4 }
53+
Constant [ <persistent> int PREG_GREP_INVERT ] { 1 }
54+
Constant [ <persistent> int PREG_NO_ERROR ] { 0 }
55+
Constant [ <persistent> int PREG_INTERNAL_ERROR ] { 1 }
56+
Constant [ <persistent> int PREG_BACKTRACK_LIMIT_ERROR ] { 2 }
57+
Constant [ <persistent> int PREG_RECURSION_LIMIT_ERROR ] { 3 }
58+
Constant [ <persistent> int PREG_BAD_UTF8_ERROR ] { 4 }
59+
Constant [ <persistent> int PREG_BAD_UTF8_OFFSET_ERROR ] { 5 }
60+
Constant [ <persistent> int PREG_JIT_STACKLIMIT_ERROR ] { 6 }
61+
Constant [ <persistent> string PCRE_VERSION ] { %s }
62+
Constant [ <persistent> int PCRE_VERSION_MAJOR ] { %d }
63+
Constant [ <persistent> int PCRE_VERSION_MINOR ] { %d }
64+
Constant [ <persistent> bool PCRE_JIT_SUPPORT ] { %d }
6565
}
6666

6767
- Functions {

0 commit comments

Comments
 (0)