ZEND_API void zend_print_zval_r_ex(zend_write_func_t write_func, zval *expr, int indent) /* {{{ */ { ZVAL_DEREF(expr); switch (Z_TYPE_P(expr)) { case IS_ARRAY: ZEND_PUTS_EX("Array\n"); if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr)) && ++Z_ARRVAL_P(expr)->u.v.nApplyCount>1) { ZEND_PUTS_EX(" *RECURSION*"); Z_ARRVAL_P(expr)->u.v.nApplyCount--; return; } print_hash(write_func, Z_ARRVAL_P(expr), indent, 0); if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr))) { Z_ARRVAL_P(expr)->u.v.nApplyCount--; } break; case IS_OBJECT: { HashTable *properties; int is_temp; zend_string *class_name = Z_OBJ_HANDLER_P(expr, get_class_name)(Z_OBJ_P(expr)); ZEND_PUTS_EX(ZSTR_VAL(class_name)); zend_string_release(class_name); ZEND_PUTS_EX(" Object\n"); if (Z_OBJ_APPLY_COUNT_P(expr) > 0) { ZEND_PUTS_EX(" *RECURSION*"); return; } if ((properties = Z_OBJDEBUG_P(expr, is_temp)) == NULL) { break; } Z_OBJ_INC_APPLY_COUNT_P(expr); print_hash(write_func, properties, indent, 1); Z_OBJ_DEC_APPLY_COUNT_P(expr); if (is_temp) { zend_hash_destroy(properties); FREE_HASHTABLE(properties); } break; } default: zend_print_zval_ex(write_func, expr, indent); break; } }
PHPAPI void php_var_dump(zval *struc, int level) /* {{{ */ { HashTable *myht; zend_string *class_name; int is_temp; int is_ref = 0; zend_ulong num; zend_string *key; zval *val; uint32_t count; if (level > 1) { php_printf("%*c", level - 1, ' '); } again: switch (Z_TYPE_P(struc)) { case IS_FALSE: php_printf("%sbool(false)\n", COMMON); break; case IS_TRUE: php_printf("%sbool(true)\n", COMMON); break; case IS_NULL: php_printf("%sNULL\n", COMMON); break; case IS_LONG: php_printf("%sint(" ZEND_LONG_FMT ")\n", COMMON, Z_LVAL_P(struc)); break; case IS_DOUBLE: php_printf("%sfloat(%.*G)\n", COMMON, (int) EG(precision), Z_DVAL_P(struc)); break; case IS_STRING: php_printf("%sstring(%zd) \"", COMMON, Z_STRLEN_P(struc)); PHPWRITE(Z_STRVAL_P(struc), Z_STRLEN_P(struc)); PUTS("\"\n"); break; case IS_ARRAY: myht = Z_ARRVAL_P(struc); if (level > 1 && ZEND_HASH_APPLY_PROTECTION(myht) && ++myht->u.v.nApplyCount > 1) { PUTS("*RECURSION*\n"); --myht->u.v.nApplyCount; return; } count = zend_array_count(myht); php_printf("%sarray(%d) {\n", COMMON, count); is_temp = 0; ZEND_HASH_FOREACH_KEY_VAL_IND(myht, num, key, val) { php_array_element_dump(val, num, key, level); } ZEND_HASH_FOREACH_END(); if (level > 1 && ZEND_HASH_APPLY_PROTECTION(myht)) { --myht->u.v.nApplyCount; } if (is_temp) { zend_hash_destroy(myht); efree(myht); } if (level > 1) { php_printf("%*c", level-1, ' '); } PUTS("}\n"); break; case IS_OBJECT: if (Z_OBJ_APPLY_COUNT_P(struc) > 0) { PUTS("*RECURSION*\n"); return; } Z_OBJ_INC_APPLY_COUNT_P(struc); myht = Z_OBJDEBUG_P(struc, is_temp); class_name = Z_OBJ_HANDLER_P(struc, get_class_name)(Z_OBJ_P(struc)); php_printf("%sobject(%s)#%d (%d) {\n", COMMON, ZSTR_VAL(class_name), Z_OBJ_HANDLE_P(struc), myht ? zend_array_count(myht) : 0); zend_string_release(class_name); if (myht) { zend_ulong num; zend_string *key; zval *val; ZEND_HASH_FOREACH_KEY_VAL_IND(myht, num, key, val) { php_object_property_dump(val, num, key, level); } ZEND_HASH_FOREACH_END(); if (is_temp) { zend_hash_destroy(myht); efree(myht); } }
static void zend_print_zval_r_to_buf(smart_str *buf, zval *expr, int indent) /* {{{ */ { switch (Z_TYPE_P(expr)) { case IS_ARRAY: smart_str_appends(buf, "Array\n"); if (Z_REFCOUNTED_P(expr)) { if (Z_IS_RECURSIVE_P(expr)) { smart_str_appends(buf, " *RECURSION*"); return; } Z_PROTECT_RECURSION_P(expr); } print_hash(buf, Z_ARRVAL_P(expr), indent, 0); if (Z_REFCOUNTED_P(expr)) { Z_UNPROTECT_RECURSION_P(expr); } break; case IS_OBJECT: { HashTable *properties; int is_temp; zend_string *class_name = Z_OBJ_HANDLER_P(expr, get_class_name)(Z_OBJ_P(expr)); smart_str_appends(buf, ZSTR_VAL(class_name)); zend_string_release(class_name); smart_str_appends(buf, " Object\n"); if (Z_IS_RECURSIVE_P(expr)) { smart_str_appends(buf, " *RECURSION*"); return; } if ((properties = Z_OBJDEBUG_P(expr, is_temp)) == NULL) { break; } Z_PROTECT_RECURSION_P(expr); print_hash(buf, properties, indent, 1); Z_UNPROTECT_RECURSION_P(expr); if (is_temp) { zend_hash_destroy(properties); FREE_HASHTABLE(properties); } break; } case IS_LONG: smart_str_append_long(buf, Z_LVAL_P(expr)); break; case IS_REFERENCE: zend_print_zval_r_to_buf(buf, Z_REFVAL_P(expr), indent); break; case IS_STRING: smart_str_append(buf, Z_STR_P(expr)); break; default: { zend_string *str = zval_get_string_func(expr); smart_str_append(buf, str); zend_string_release(str); } break; } }