]> granicus.if.org Git - php/commitdiff
- Fixed var_export() to show public, protected and private modifiers properly.
authorDerick Rethans <derick@php.net>
Sat, 3 Jan 2004 13:51:02 +0000 (13:51 +0000)
committerDerick Rethans <derick@php.net>
Sat, 3 Jan 2004 13:51:02 +0000 (13:51 +0000)
- Exported (un)mangle_property_name.

NEWS
Zend/zend.c
Zend/zend_API.c
Zend/zend_compile.c
Zend/zend_compile.h
Zend/zend_execute.c
Zend/zend_object_handlers.c
Zend/zend_reflection_api.c
ext/reflection/php_reflection.c
ext/standard/basic_functions.c
ext/standard/var.c

diff --git a/NEWS b/NEWS
index 3e5923b5013f4d1440b866185c790b8ce31c3920..ce00ed450279b325a97e263711e124e8c14aef66 100644 (file)
--- 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)
index 59e336c116c53be68f3f8023b7e2d5acffdf7191..7907e38c0ed096c33629666916314f41ce6bec19 100644 (file)
@@ -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]=='*') {
index 20a692111062d9cde8a4b1df280a50a6ef9ddcdc..3bb972545ff647262daaa7782c2e212089cb44ca 100644 (file)
@@ -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);
                        }
index 639ef3c6d84340cbba09759bd0c345df7820a5ca..6ae3e40d27e85b6b0f1381e0571fc9c231010d11 100644 (file)
@@ -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;
 
index f686bdb46039e4f01babc4c2bce39444d170b43b..a7938f762cda4e013d1bf50dff707b71d35162a8 100644 (file)
@@ -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
index f7083765b980bf1e9ed48260364c7c0d2cb06231..f3acee7d1fe2c034abbf2805f5c9556f01f5b3d9 100644 (file)
@@ -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++;
index f3884dbd9d8a11d2919aa1ba0cba6705257c05ef..01acba17a03611c10ddaf02504c7d74df6f6aace 100644 (file)
@@ -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) {
index a62b49bd00055595965d4e26c2180a2395bbb989..77fe2f9aec4cbba46354b434100b7139d31bcf0e 100644 (file)
@@ -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;
index a62b49bd00055595965d4e26c2180a2395bbb989..77fe2f9aec4cbba46354b434100b7139d31bcf0e 100644 (file)
@@ -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;
index 17ae1145020d9eef7a888e10312c950827f13e9e..29e0df1c438ab0fef70ff81cc5e7a94a47ef5ba3 100644 (file)
@@ -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);
index 886142afffc36c0e1b3b50d4e0f440cff927c7e8..ef53a15d0ec274f837c34a78b6e8b836a6fd2bf5 100644 (file)
@@ -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");
        }