com php-src: make var_dump more acceptable: Zend/test s/type_declarations/typed_properties_037.phpt e xt/standard/var.c
| From: | Bob Weinand | Date: | Tue, 05 Apr 2016 01:10:20 +0000 |
| Subject: | com php-src: make var_dump more acceptable: Zend/test s/type_declarations/typed_properties_037.phpt e xt/standard/var.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-95583@lists.php.net to get a copy of this message | ||
Commit: dd6d5ad051b70c21e7b6e57c3d7dc3b5079883a4
Author: Joe Watkins <krakjoe@php.net> Tue, 5 Apr 2016 02:10:20 +0100
Parents: f13b0a3039d7eebde9dd797a4e185bc9b2762bc5
Branches: typed_ref_properties
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=dd6d5ad051b70c21e7b6e57c3d7dc3b5079883a4
Log:
make var_dump more acceptable
Changed paths:
A Zend/tests/type_declarations/typed_properties_037.phpt
M ext/standard/var.c
Diff:
diff --git a/Zend/tests/type_declarations/typed_properties_037.phpt
b/Zend/tests/type_declarations/typed_properties_037.phpt
new file mode 100644
index 0000000..8bdd674
--- /dev/null
+++ b/Zend/tests/type_declarations/typed_properties_037.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Test typed properties var_dump uninitialized
+--FILE--
+<?php
+$foo = new class {
+ public int $bar = 10, $qux;
+};
+
+var_dump($foo);
+--EXPECTF--
+object(class@anonymous)#%d (%d) {
+ ["bar"]=>
+ int(10)
+ ["qux"]=>
+ uninitialized(integer)
+}
+
diff --git a/ext/standard/var.c b/ext/standard/var.c
index bc76699..a7a7063 100644
--- a/ext/standard/var.c
+++ b/ext/standard/var.c
@@ -48,7 +48,7 @@ static void php_array_element_dump(zval *zv, zend_ulong index, zend_string *key,
}
/* }}} */
-static void php_object_property_dump(zval *zv, zend_ulong index, zend_string *key, int level) /*
{{{ */
+static void php_object_property_dump(zend_property_info *prop_info, zval *zv, zend_ulong index,
zend_string *key, int level) /* {{{ */
{
const char *prop_name, *class_name;
@@ -71,7 +71,16 @@ static void php_object_property_dump(zval *zv, zend_ulong index, zend_string *ke
}
ZEND_PUTS("]=>\n");
}
- php_var_dump(zv, level + 2);
+
+ if (prop_info && Z_TYPE_P(zv) == IS_NULL) {
+ php_printf("%*cuninitialized(%s)\n",
+ level + 1, ' ',
+ (prop_info->type == IS_OBJECT) ?
+ ZSTR_VAL(prop_info->type_name) :
+ zend_get_type_by_const(prop_info->type));
+ } else {
+ php_var_dump(zv, level + 2);
+ }
}
/* }}} */
@@ -156,7 +165,9 @@ again:
zval *val;
ZEND_HASH_FOREACH_KEY_VAL_IND(myht, num, key, val) {
- php_object_property_dump(val, num, key, level);
+ zend_property_info *prop_info = zend_object_fetch_property_type_info_ex(struc, key, NULL);
+
+ php_object_property_dump(prop_info, val, num, key, level);
} ZEND_HASH_FOREACH_END();
if (is_temp) {
zend_hash_destroy(myht);