[xdebug-dev] svn: /xdebug/trunk/ tests/bug00328.phpt xdebug.dsp xdebug_var.c

From: Derick Rethans <derick[@]derickrethans.nl>
Date: Mon, 28 Dec 2009 17:34:25 +0000

derick Mon, 28 Dec 2009 17:34:25 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=3168

Log:
- Fixed bug #494: Private attributes of parent class unavailable when
  inheriting.
- Fixed bug #328: Private properties are incorrectly enumerated in case of
  extended classes.

Changed paths:
    A xdebug/trunk/tests/bug00328.phpt
    D xdebug/trunk/xdebug.dsp
    U xdebug/trunk/xdebug_var.c

Added: xdebug/trunk/tests/bug00328.phpt
===================================================================
--- xdebug/trunk/tests/bug00328.phpt (rev 0)
+++ xdebug/trunk/tests/bug00328.phpt 2009-12-28 17:34:25 UTC (rev 3168)
@@ -0,0 +1,29 @@
+--TEST--
+Test for bug #328: (Private properties are incorrectly enumerated in case of extended classes)
+--INI--
+html_errors=1
+--FILE--
+<?php
+class Daddy
+{
+ private $bar = 42;
+ protected $pro = 242;
+ public $pub = 342;
+}
+class Inherit extends Daddy
+{
+ private $bar = 43;
+ protected $pro = 243;
+ public $pub = 343;
+}
+$a = new Inherit;
+var_dump( $a );
+?>
+--EXPECT--
+<pre class='xdebug-var-dump' dir='ltr'>
+<b>object</b>(<i>Inherit</i>)[<i>1</i>]
+ <i>private</i> 'bar' <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>43</font>
+ <i>protected</i> 'pro' <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>243</font>
+ <i>public</i> 'pub' <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>343</font>
+ <i>private</i> 'bar' <small>(Daddy)</small> <font color='#888a85'>=&gt;</font> <small>int</small> <font color='#4e9a06'>42</font>
+</pre>

Deleted: xdebug/trunk/xdebug.dsp
===================================================================
(Binary files differ)

Modified: xdebug/trunk/xdebug_var.c
===================================================================
--- xdebug/trunk/xdebug_var.c 2009-12-28 17:32:30 UTC (rev 3167)
+++ xdebug/trunk/xdebug_var.c 2009-12-28 17:34:25 UTC (rev 3168)
@@ -218,7 +218,7 @@
         int level, debug_zval;
         xdebug_str *str;
         xdebug_var_export_options *options;
- char *prop_name, *class_name, *modifier;
+ char *prop_name, *class_name, *modifier, *prop_class_name;
 #if !defined(PHP_VERSION_ID) || PHP_VERSION_ID < 50300
         TSRMLS_FETCH();
 #endif
@@ -227,13 +227,18 @@
         str = va_arg(args, struct xdebug_str*);
         debug_zval = va_arg(args, int);
         options = va_arg(args, xdebug_var_export_options*);
+ class_name = va_arg(args, char *);

         if (options->runtime[level].current_element_nr >= options->runtime[level].start_element_nr &&
                 options->runtime[level].current_element_nr < options->runtime[level].end_element_nr)
         {
                 if (hash_key->nKeyLength != 0) {
- modifier = xdebug_get_property_info(hash_key->arKey, hash_key->nKeyLength, &prop_name, &class_name);
- xdebug_str_add(str, xdebug_sprintf("%s $%s = ", modifier, prop_name), 1);
+ modifier = xdebug_get_property_info(hash_key->arKey, hash_key->nKeyLength, &prop_name, &prop_class_name);
+ if (strcmp(modifier, "private") != 0 || strcmp(class_name, prop_class_name) == 0) {
+ xdebug_str_add(str, xdebug_sprintf("%s $%s = ", modifier, prop_name), 1);
+ } else {
+ xdebug_str_add(str, xdebug_sprintf("%s ${%s}:%s = ", modifier, prop_class_name, prop_name), 1);
+ }
                 }
                 xdebug_var_export(zv, str, level + 2, debug_zval, options TSRMLS_CC);
                 xdebug_str_addl(str, "; ", 2, 0);
@@ -319,14 +324,13 @@

                                 zend_get_object_classname(*struc, &class_name, &class_name_len TSRMLS_CC);
                                 xdebug_str_add(str, xdebug_sprintf("class %s { ", class_name), 1);
- efree(class_name);

                                 if (level <= options->max_depth) {
                                         options->runtime[level].current_element_nr = 0;
                                         options->runtime[level].start_element_nr = 0;
                                         options->runtime[level].end_element_nr = options->max_children;

- zend_hash_apply_with_arguments(myht XDEBUG_ZEND_HASH_APPLY_TSRMLS_CC, (apply_func_args_t) xdebug_object_element_export, 4, level, str, debug_zval, options);
+ zend_hash_apply_with_arguments(myht XDEBUG_ZEND_HASH_APPLY_TSRMLS_CC, (apply_func_args_t) xdebug_object_element_export, 5, level, str, debug_zval, options, class_name);
                                         /* Remove the ", " at the end of the string */
                                         if (myht->nNumOfElements > 0) {
                                                 xdebug_str_chop(str, 2);
@@ -335,6 +339,7 @@
                                         xdebug_str_addl(str, "...", 3, 0);
                                 }
                                 xdebug_str_addl(str, " }", 2, 0);
+ efree(class_name);
                         } else {
                                 xdebug_str_addl(str, "...", 3, 0);
                         }
@@ -680,7 +685,12 @@

                 if (hash_key->nKeyLength != 0) {
                         modifier = xdebug_get_property_info(hash_key->arKey, hash_key->nKeyLength, &prop_name, &prop_class_name);
- xdebug_xml_add_attribute(node, "name", prop_name);
+ if (strcmp(modifier, "private") != 0 || strcmp(class_name, prop_class_name) == 0) {
+ xdebug_xml_add_attribute(node, "name", prop_name);
+ } else {
+ char *tmpname = xdebug_sprintf("{%s}:%s", prop_class_name, prop_name);
+ xdebug_xml_add_attribute(node, "name", tmpname);
+ }

                         if (strcmp(modifier, "private") != 0 || strcmp(class_name, prop_class_name) == 0) {
                                 if (parent_name) {
@@ -698,9 +708,7 @@

                         xdebug_xml_add_child(parent, node);

- if (strcmp(modifier, "private") != 0 || strcmp(class_name, prop_class_name) == 0) {
- xdebug_var_export_xml_node(zv, full_name, node, options, level + 1 TSRMLS_CC);
- }
+ xdebug_var_export_xml_node(zv, full_name, node, options, level + 1 TSRMLS_CC);
                 }
         }
         options->runtime[level].current_element_nr++;
@@ -906,7 +914,7 @@
         xdebug_str *str;
         xdebug_var_export_options *options;
         char *key;
- char *prop_name, *class_name, *modifier;
+ char *prop_name, *class_name, *modifier, *prop_class_name;
 #if !defined(PHP_VERSION_ID) || PHP_VERSION_ID < 50300
         TSRMLS_FETCH();
 #endif
@@ -915,6 +923,7 @@
         str = va_arg(args, struct xdebug_str*);
         debug_zval = va_arg(args, int);
         options = va_arg(args, xdebug_var_export_options*);
+ class_name = va_arg(args, char *);

         if (options->runtime[level].current_element_nr >= options->runtime[level].start_element_nr &&
                 options->runtime[level].current_element_nr < options->runtime[level].end_element_nr)
@@ -923,8 +932,12 @@

                 key = hash_key->arKey;
                 if (hash_key->nKeyLength != 0) {
- modifier = xdebug_get_property_info(hash_key->arKey, hash_key->nKeyLength, &prop_name, &class_name);
- xdebug_str_add(str, xdebug_sprintf("<i>%s</i> '%s' <font color='%s'>=&gt;</font> ", modifier, prop_name, COLOR_POINTER), 1);
+ modifier = xdebug_get_property_info(hash_key->arKey, hash_key->nKeyLength, &prop_name, &prop_class_name);
+ if (strcmp(modifier, "private") != 0 || strcmp(class_name, prop_class_name) == 0) {
+ xdebug_str_add(str, xdebug_sprintf("<i>%s</i> '%s' <font color='%s'>=&gt;</font> ", modifier, prop_name, COLOR_POINTER), 1);
+ } else {
+ xdebug_str_add(str, xdebug_sprintf("<i>%s</i> '%s' <small>(%s)</small> <font color='%s'>=&gt;</font> ", modifier, prop_name, prop_class_name, COLOR_POINTER), 1);
+ }
                 }
                 xdebug_var_export_fancy(zv, str, level + 1, debug_zval, options TSRMLS_CC);
         }
@@ -1017,7 +1030,7 @@
                                         options->runtime[level].start_element_nr = 0;
                                         options->runtime[level].end_element_nr = options->max_children;

- zend_hash_apply_with_arguments(myht XDEBUG_ZEND_HASH_APPLY_TSRMLS_CC, (apply_func_args_t) xdebug_object_element_export_fancy, 4, level, str, debug_zval, options);
+ zend_hash_apply_with_arguments(myht XDEBUG_ZEND_HASH_APPLY_TSRMLS_CC, (apply_func_args_t) xdebug_object_element_export_fancy, 5, level, str, debug_zval, options, Z_OBJCE_PP(struc)->name);
                                 } else {
                                         xdebug_str_add(str, xdebug_sprintf("%*s...\n", (level * 4) - 2, ""), 1);
                                 }
Received on Mon Dec 28 2009 - 17:34:25 GMT

This archive was generated by hypermail 2.2.0 : Sun Jun 24 2018 - 04:00:03 BST