From: Derick Rethans Date: Sat, 3 Jan 2004 13:51:02 +0000 (+0000) Subject: - Fixed var_export() to show public, protected and private modifiers properly. X-Git-Tag: php_ibase_before_split~397 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6923a16c2651b09f70ab0670e99d7eadc319f131;p=php - Fixed var_export() to show public, protected and private modifiers properly. - Exported (un)mangle_property_name. --- diff --git a/NEWS b/NEWS index 3e5923b501..ce00ed4502 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,8 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? 2004, PHP 5 RC1 +- Fixed var_export() to show public, protected and private modifiers properly. + (Derick) - Fixed problems with longlong values in mysqli. (Georg) - Fixed class name case preserving of user defined classes. (Marcus) - Fixed bug #26762 (unserialize() produces lowercase classnames). (Marcus) diff --git a/Zend/zend.c b/Zend/zend.c index 59e336c116..7907e38c0e 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -138,7 +138,7 @@ static void print_hash(HashTable *ht, int indent, zend_bool is_object TSRMLS_DC) if (is_object) { char *prop_name, *class_name; - unmangle_property_name(string_key, &class_name, &prop_name); + zend_unmangle_property_name(string_key, &class_name, &prop_name); ZEND_PUTS(prop_name); if (class_name) { if (class_name[0]=='*') { diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 20a6921110..3bb972545f 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -1763,7 +1763,7 @@ ZEND_API int zend_declare_property(zend_class_entry *ce, char *name, int name_le char *priv_name; int priv_name_length; - mangle_property_name(&priv_name, &priv_name_length, ce->name, ce->name_length, name, name_length, ce->type & ZEND_INTERNAL_CLASS); + zend_mangle_property_name(&priv_name, &priv_name_length, ce->name, ce->name_length, name, name_length, ce->type & ZEND_INTERNAL_CLASS); zend_hash_update(target_symbol_table, priv_name, priv_name_length+1, &property, sizeof(zval *), NULL); property_info.name = priv_name; property_info.name_length = priv_name_length; @@ -1773,7 +1773,7 @@ ZEND_API int zend_declare_property(zend_class_entry *ce, char *name, int name_le char *prot_name; int prot_name_length; - mangle_property_name(&prot_name, &prot_name_length, "*", 1, name, name_length, ce->type & ZEND_INTERNAL_CLASS); + zend_mangle_property_name(&prot_name, &prot_name_length, "*", 1, name, name_length, ce->type & ZEND_INTERNAL_CLASS); zend_hash_update(target_symbol_table, prot_name, prot_name_length+1, &property, sizeof(zval *), NULL); property_info.name = prot_name; property_info.name_length = prot_name_length; @@ -1784,7 +1784,7 @@ ZEND_API int zend_declare_property(zend_class_entry *ce, char *name, int name_le char *prot_name; int prot_name_length; - mangle_property_name(&prot_name, &prot_name_length, "*", 1, name, name_length, ce->type & ZEND_INTERNAL_CLASS); + zend_mangle_property_name(&prot_name, &prot_name_length, "*", 1, name, name_length, ce->type & ZEND_INTERNAL_CLASS); zend_hash_del(target_symbol_table, prot_name, prot_name_length+1); pefree(prot_name, ce->type & ZEND_INTERNAL_CLASS); } diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 639ef3c6d8..6ae3e40d27 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -1814,7 +1814,7 @@ static zend_bool do_inherit_property_access_check(HashTable *target_ht, zend_pro char *prot_name; int prot_name_length; - mangle_property_name(&prot_name, &prot_name_length, "*", 1, child_info->name, child_info->name_length, ce->type & ZEND_INTERNAL_CLASS); + zend_mangle_property_name(&prot_name, &prot_name_length, "*", 1, child_info->name, child_info->name_length, ce->type & ZEND_INTERNAL_CLASS); if (child_info->flags & ZEND_ACC_STATIC) { zval **prop; if (zend_hash_find(parent_ce->static_members, prot_name, prot_name_length+1, (void**)&prop) == SUCCESS) { @@ -2421,7 +2421,7 @@ void zend_do_implements_interface(znode *interface_znode TSRMLS_DC) } -void mangle_property_name(char **dest, int *dest_length, char *src1, int src1_length, char *src2, int src2_length, int internal) +ZEND_API void zend_mangle_property_name(char **dest, int *dest_length, char *src1, int src1_length, char *src2, int src2_length, int internal) { char *prop_name; int prop_name_length; @@ -2437,7 +2437,7 @@ void mangle_property_name(char **dest, int *dest_length, char *src1, int src1_le } -void unmangle_property_name(char *mangled_property, char **class_name, char **prop_name) +ZEND_API void zend_unmangle_property_name(char *mangled_property, char **class_name, char **prop_name) { *prop_name = *class_name = NULL; diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h index f686bdb460..a7938f762c 100644 --- a/Zend/zend_compile.h +++ b/Zend/zend_compile.h @@ -465,8 +465,8 @@ ZEND_API void destroy_zend_function(zend_function *function TSRMLS_DC); ZEND_API void destroy_zend_class(zend_class_entry **pce); void zend_class_add_ref(zend_class_entry **ce); -void mangle_property_name(char **dest, int *dest_length, char *src1, int src1_length, char *src2, int src2_length, int internal); -void unmangle_property_name(char *mangled_property, char **prop_name, char **class_name); +ZEND_API void zend_mangle_property_name(char **dest, int *dest_length, char *src1, int src1_length, char *src2, int src2_length, int internal); +ZEND_API void zend_unmangle_property_name(char *mangled_property, char **prop_name, char **class_name); #define ZEND_FUNCTION_DTOR (void (*)(void *)) destroy_zend_function #define ZEND_CLASS_DTOR (void (*)(void *)) destroy_zend_class diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index f7083765b9..f3acee7d1f 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -3645,7 +3645,7 @@ int zend_fe_fetch_handler(ZEND_OPCODE_HANDLER_ARGS) zend_hash_move_forward(fe_ht); } while (zend_check_property_access(zobj, str_key TSRMLS_CC) != SUCCESS); - unmangle_property_name(str_key, &class_name, &prop_name); + zend_unmangle_property_name(str_key, &class_name, &prop_name); str_key_len = strlen(prop_name); str_key = estrndup(prop_name, str_key_len); str_key_len++; diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c index f3884dbd9d..01acba17a0 100644 --- a/Zend/zend_object_handlers.c +++ b/Zend/zend_object_handlers.c @@ -248,7 +248,7 @@ ZEND_API int zend_check_property_access(zend_object *zobj, char *prop_info_name char *class_name, *prop_name; zval member; - unmangle_property_name(prop_info_name, &class_name, &prop_name); + zend_unmangle_property_name(prop_info_name, &class_name, &prop_name); ZVAL_STRING(&member, prop_name, 0); property_info = zend_get_property_info(zobj, &member, 1 TSRMLS_CC); if (!property_info) { diff --git a/Zend/zend_reflection_api.c b/Zend/zend_reflection_api.c index a62b49bd00..77fe2f9aec 100644 --- a/Zend/zend_reflection_api.c +++ b/Zend/zend_reflection_api.c @@ -616,7 +616,7 @@ static void _property_string(string *str, zend_property_info *prop, char *prop_n string_printf(str, "static "); } - unmangle_property_name(prop->name, &class_name, &prop_name); + zend_unmangle_property_name(prop->name, &class_name, &prop_name); string_printf(str, "$%s", prop_name); } @@ -758,7 +758,7 @@ static void reflection_property_factory(zend_class_entry *ce, zend_property_info property_reference *reference; char *class_name, *prop_name; - unmangle_property_name(prop->name, &class_name, &prop_name); + zend_unmangle_property_name(prop->name, &class_name, &prop_name); if (!(prop->flags & ZEND_ACC_PRIVATE)) { /* we have to seach the class hierarchy for this (implicit) public or protected property */ @@ -1866,7 +1866,7 @@ ZEND_METHOD(reflection_class, getDefaultProperties) zend_hash_get_current_key_ex(&ce->default_properties, &key, &key_len, &num_index, 0, &pos); zend_hash_move_forward_ex(&ce->default_properties, &pos); - unmangle_property_name(key, &class_name, &prop_name); + zend_unmangle_property_name(key, &class_name, &prop_name); if (class_name && class_name[0] != '*' && strcmp(class_name, ce->name)) { /* filter privates from base classes */ continue; diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index a62b49bd00..77fe2f9aec 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -616,7 +616,7 @@ static void _property_string(string *str, zend_property_info *prop, char *prop_n string_printf(str, "static "); } - unmangle_property_name(prop->name, &class_name, &prop_name); + zend_unmangle_property_name(prop->name, &class_name, &prop_name); string_printf(str, "$%s", prop_name); } @@ -758,7 +758,7 @@ static void reflection_property_factory(zend_class_entry *ce, zend_property_info property_reference *reference; char *class_name, *prop_name; - unmangle_property_name(prop->name, &class_name, &prop_name); + zend_unmangle_property_name(prop->name, &class_name, &prop_name); if (!(prop->flags & ZEND_ACC_PRIVATE)) { /* we have to seach the class hierarchy for this (implicit) public or protected property */ @@ -1866,7 +1866,7 @@ ZEND_METHOD(reflection_class, getDefaultProperties) zend_hash_get_current_key_ex(&ce->default_properties, &key, &key_len, &num_index, 0, &pos); zend_hash_move_forward_ex(&ce->default_properties, &pos); - unmangle_property_name(key, &class_name, &prop_name); + zend_unmangle_property_name(key, &class_name, &prop_name); if (class_name && class_name[0] != '*' && strcmp(class_name, ce->name)) { /* filter privates from base classes */ continue; diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 17ae114502..29e0df1c43 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -2564,7 +2564,7 @@ PHP_FUNCTION(print_r) php_start_ob_buffer (NULL, 0, 1 TSRMLS_CC); } - zend_print_pval_r(var, 0 TSRMLS_CC); + zend_print_zval_r(var, 0 TSRMLS_CC); if (i) { php_ob_get_buffer (return_value TSRMLS_CC); diff --git a/ext/standard/var.c b/ext/standard/var.c index 886142afff..ef53a15d0e 100644 --- a/ext/standard/var.c +++ b/ext/standard/var.c @@ -310,12 +310,24 @@ static int php_array_element_export(zval **zv, int num_args, va_list args, zend_ static int php_object_element_export(zval **zv, int num_args, va_list args, zend_hash_key *hash_key) { int level; + char *prop_name, *class_name; TSRMLS_FETCH(); level = va_arg(args, int); if (hash_key->nKeyLength != 0) { - php_printf("%*cvar $%s = ", level + 1, ' ', hash_key->arKey); + php_printf("%*c", level + 1, ' '); + zend_unmangle_property_name(hash_key->arKey, &class_name, &prop_name); + if (class_name) { + if (class_name[0] == '*') { + php_printf("protected"); + } else { + php_printf("private"); + } + } else { + php_printf("public"); + } + php_printf(" $%s = ", prop_name); php_var_export(zv, level + 2 TSRMLS_CC); PUTS (";\n"); }