Skip to content

Commit 01a29c3

Browse files
committed
ext/standard/var.c: show unset properties
1 parent dfe9ab7 commit 01a29c3

22 files changed

+86
-45
lines changed

Zend/tests/019.phpt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,15 +1237,23 @@ object(Point)#%d (3) {
12371237
["lable"]=>
12381238
string(6) "Point1"
12391239
}
1240-
object(Point)#%d (2) {
1240+
object(Point)#%d (3) {
1241+
["x"]=>
1242+
unset
12411243
["y"]=>
12421244
int(40)
12431245
["lable"]=>
12441246
string(6) "Point1"
12451247
}
12461248
bool(false)
12471249
bool(true)
1248-
object(Point)#%d (0) {
1250+
object(Point)#%d (3) {
1251+
["x"]=>
1252+
unset
1253+
["y"]=>
1254+
unset
1255+
["lable"]=>
1256+
unset
12491257
}
12501258
bool(true)
12511259
bool(false)

Zend/tests/ctor_promotion_untyped_default.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ var_dump(new B);
2121

2222
?>
2323
--EXPECT--
24-
object(B)#1 (1) {
24+
object(B)#1 (2) {
2525
["untyped"]=>
2626
NULL
2727
["typed"]=>

Zend/tests/type_declarations/typed_properties_037.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ $foo = new class {
99
var_dump($foo);
1010
?>
1111
--EXPECTF--
12-
object(class@anonymous)#%d (1) {
12+
object(class@anonymous)#%d (2) {
1313
["bar"]=>
1414
int(10)
1515
["qux"]=>

Zend/tests/type_declarations/typed_properties_052.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ $obj = new A;
1818
var_dump($obj);
1919
?>
2020
--EXPECT--
21-
object(A)#1 (0) {
21+
object(A)#1 (6) {
2222
["a1"]=>
2323
uninitialized(A)
2424
["b1"]=>

Zend/tests/type_declarations/typed_properties_059.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ $x = new A;
1717
var_dump($x);
1818
?>
1919
--EXPECT--
20-
object(A)#1 (0) {
20+
object(A)#1 (4) {
2121
["a2"]=>
2222
uninitialized(int)
2323
["b2"]=>

Zend/tests/type_declarations/typed_properties_072.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var_dump($test->val);
1818

1919
?>
2020
--EXPECT--
21-
object(Test)#1 (0) {
21+
object(Test)#1 (1) {
2222
["val"]=>
2323
uninitialized(int)
2424
}

Zend/tests/type_declarations/typed_properties_073.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@ var_dump($test, $val);
2323

2424
?>
2525
--EXPECT--
26-
object(Test)#1 (1) {
26+
object(Test)#1 (2) {
2727
["prop"]=>
2828
string(2) "42"
2929
["val"]=>
3030
uninitialized(int)
3131
}
3232
int(42)
33-
object(Test)#1 (1) {
33+
object(Test)#1 (2) {
3434
["prop"]=>
3535
&int(42)
3636
["val"]=>
3737
uninitialized(int)
3838
}
39-
object(Test)#1 (1) {
39+
object(Test)#1 (2) {
4040
["prop"]=>
4141
&string(1) "x"
4242
["val"]=>

Zend/tests/type_declarations/typed_properties_074.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ var_dump($test->prop);
2626

2727
?>
2828
--EXPECT--
29-
object(Test)#1 (1) {
29+
object(Test)#1 (2) {
3030
["prop"]=>
3131
&string(1) "x"
3232
["val"]=>
3333
uninitialized(int)
3434
}
3535
Value of type string returned from Test::__get() must be compatible with unset property Test::$val of type int
36-
object(Test)#1 (1) {
36+
object(Test)#1 (2) {
3737
["prop"]=>
3838
&string(1) "x"
3939
["val"]=>

Zend/tests/type_declarations/typed_properties_086.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var_dump($t);
2020

2121
?>
2222
--EXPECT--
23-
object(T)#1 (1) {
23+
object(T)#1 (2) {
2424
["i"]=>
2525
uninitialized(int)
2626
["1"]=>

Zend/tests/type_declarations/typed_properties_093.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var_dump($test);
2525
?>
2626
--EXPECT--
2727
Cannot assign string to property Test::$prop of type int
28-
object(Test)#2 (0) {
28+
object(Test)#2 (1) {
2929
["prop"]=>
3030
uninitialized(int)
3131
}

Zend/tests/type_declarations/typed_properties_095.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ var_dump(_ZendTestClass::$staticIntProp);
6363
int(123)
6464
Cannot assign string to property _ZendTestClass::$intProp of type int
6565
Cannot assign _ZendTestClass to property _ZendTestClass::$classProp of type ?stdClass
66-
object(_ZendTestClass)#1 (3) {
66+
object(_ZendTestClass)#1 (6) {
6767
["intProp"]=>
6868
int(456)
6969
["classProp"]=>
@@ -81,7 +81,7 @@ object(_ZendTestClass)#1 (3) {
8181
int(123)
8282
Cannot assign string to property _ZendTestClass::$intProp of type int
8383
Cannot assign Test to property _ZendTestClass::$classProp of type ?stdClass
84-
object(Test)#4 (3) {
84+
object(Test)#4 (6) {
8585
["intProp"]=>
8686
int(456)
8787
["classProp"]=>

Zend/tests/type_declarations/typed_properties_096.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var_dump($test);
3232
?>
3333
--EXPECT--
3434
Cannot assign int to property Test1::$prop of type Foobar
35-
object(Test1)#1 (1) {
35+
object(Test1)#1 (2) {
3636
["prop"]=>
3737
uninitialized(Foobar)
3838
["prop2"]=>

Zend/tests/type_declarations/typed_properties_101.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ $test->dump();
1919

2020
?>
2121
--EXPECTF--
22-
object(Test)#1 (0) {
22+
object(Test)#1 (3) {
2323
["public"]=>
2424
uninitialized(bool)
2525
["protected":protected]=>
2626
uninitialized(float)
2727
["private":"Test":private]=>
2828
uninitialized(string)
2929
}
30-
object(Test)#1 (0) refcount(%d){
30+
object(Test)#1 (3) refcount(%d){
3131
["public"]=>
3232
uninitialized(bool)
3333
["protected":protected]=>

Zend/tests/type_declarations/union_types/internal_trait_use_typed_union.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var_dump($types, (string)$types[0], (string)$types[1]);
2020
?>
2121
===DONE===
2222
--EXPECT--
23-
object(C)#1 (1) {
23+
object(C)#1 (2) {
2424
["testProp"]=>
2525
NULL
2626
["classUnionProp"]=>

Zend/tests/unset_prop_recursion.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ object(Node)#2 (2) {
4848
object(Node)#1 (2) {
4949
["parent"]=>
5050
NULL
51+
["children"]=>
52+
unset
5153
}
5254
["children"]=>
5355
array(0) {
@@ -58,6 +60,8 @@ object(Node)#3 (2) {
5860
object(Node)#1 (2) {
5961
["parent"]=>
6062
NULL
63+
["children"]=>
64+
unset
6165
}
6266
["children"]=>
6367
array(0) {

ext/standard/tests/directory/DirectoryClass_basic_001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Class [ <internal%s> class Directory ] {
6464
}
6565
}
6666
Cannot instantiate a valid Directory directly:
67-
object(Directory)#%d (0) {
67+
object(Directory)#%d (2) {
6868
["path"]=>
6969
uninitialized(string)
7070
["handle"]=>

ext/standard/tests/serialize/bug68976.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ var_dump($data);
2828
--EXPECT--
2929
array(2) {
3030
[0]=>
31-
object(evilClass)#1 (0) {
31+
object(evilClass)#1 (1) {
32+
["name"]=>
33+
unset
3234
}
3335
[1]=>
3436
int(1)

ext/standard/var.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,13 @@ static void php_object_property_dump(zend_property_info *prop_info, zval *zv, ze
7575
}
7676

7777
if (Z_TYPE_P(zv) == IS_UNDEF) {
78-
ZEND_ASSERT(ZEND_TYPE_IS_SET(prop_info->type));
79-
zend_string *type_str = zend_type_to_string(prop_info->type);
80-
php_printf("%*cuninitialized(%s)\n",
81-
level + 1, ' ', ZSTR_VAL(type_str));
82-
zend_string_release(type_str);
78+
if (prop_info && ZEND_TYPE_IS_SET(prop_info->type)) {
79+
zend_string *type_str = zend_type_to_string(prop_info->type);
80+
php_printf("%*cuninitialized(%s)\n", level + 1, ' ', ZSTR_VAL(type_str));
81+
zend_string_release(type_str);
82+
} else {
83+
php_printf("%*cunset\n", level + 1, ' ');
84+
}
8385
} else {
8486
php_var_dump(zv, level + 2);
8587
}
@@ -168,7 +170,7 @@ PHPAPI void php_var_dump(zval *struc, int level) /* {{{ */
168170
}
169171

170172
class_name = Z_OBJ_HANDLER_P(struc, get_class_name)(Z_OBJ_P(struc));
171-
php_printf("%sobject(%s)#%d (%d) {\n", COMMON, ZSTR_VAL(class_name), Z_OBJ_HANDLE_P(struc), zend_array_count(myht));
173+
php_printf("%sobject(%s)#%d (%d) {\n", COMMON, ZSTR_VAL(class_name), Z_OBJ_HANDLE_P(struc), zend_hash_num_elements(myht));
172174
zend_string_release_ex(class_name, 0);
173175

174176
zend_ulong num;
@@ -185,9 +187,7 @@ PHPAPI void php_var_dump(zval *struc, int level) /* {{{ */
185187
}
186188
}
187189

188-
if (!Z_ISUNDEF_P(val) || prop_info) {
189-
php_object_property_dump(prop_info, val, num, key, level);
190-
}
190+
php_object_property_dump(prop_info, val, num, key, level);
191191
} ZEND_HASH_FOREACH_END();
192192
zend_release_properties(myht);
193193

@@ -368,7 +368,7 @@ PHPAPI void php_debug_zval_dump(zval *struc, int level) /* {{{ */
368368
}
369369

370370
class_name = Z_OBJ_HANDLER_P(struc, get_class_name)(Z_OBJ_P(struc));
371-
php_printf("object(%s)#%d (%d) refcount(%u){\n", ZSTR_VAL(class_name), Z_OBJ_HANDLE_P(struc), zend_array_count(myht), Z_REFCOUNT_P(struc));
371+
php_printf("object(%s)#%d (%d) refcount(%u){\n", ZSTR_VAL(class_name), Z_OBJ_HANDLE_P(struc), zend_hash_num_elements(myht), Z_REFCOUNT_P(struc));
372372
zend_string_release_ex(class_name, 0);
373373

374374
ZEND_HASH_FOREACH_KEY_VAL(myht, index, key, val) {

tests/classes/property_recreate_private.phpt

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ var_dump($c);
4747
echo "\nUnset a private property, and attempt to recreate at global scope (expecting failure):\n";
4848
$c = new C;
4949
$c->unsetPrivate();
50-
$c->p = 'this will fail';
50+
try {
51+
$c->p = 'this will fail';
52+
} catch (Throwable $e) {
53+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
54+
}
5155
var_dump($c);
5256
?>
5357
===DONE===
@@ -59,13 +63,17 @@ object(D)#%d (1) {
5963
}
6064

6165
Unset superclass's private property, and recreate it as public in subclass:
62-
object(D)#%d (1) {
66+
object(D)#%d (2) {
67+
["p":"C":private]=>
68+
unset
6369
["p"]=>
6470
string(12) "changed in D"
6571
}
6672

6773
Unset superclass's private property, and recreate it as public at global scope:
68-
object(D)#%d (1) {
74+
object(D)#%d (2) {
75+
["p":"C":private]=>
76+
unset
6977
["p"]=>
7078
string(34) "this will create a public property"
7179
}
@@ -78,8 +86,9 @@ object(C)#%d (1) {
7886
}
7987

8088
Unset a private property, and attempt to recreate at global scope (expecting failure):
81-
82-
Fatal error: Uncaught Error: Cannot access private property C::$p in %s:%d
83-
Stack trace:
84-
#0 {main}
85-
thrown in %s on line %d
89+
Error: Cannot access private property C::$p
90+
object(C)#%d (1) {
91+
["p":"C":private]=>
92+
unset
93+
}
94+
===DONE===

tests/lang/foreachLoopObjects.003.phpt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,13 @@ object(C)#%d (17) {
232232

233233
Removing properties from an object.
234234
string(10) "Original a"
235-
object(C)#%d (2) {
235+
object(C)#%d (5) {
236+
["a"]=>
237+
unset
238+
["b"]=>
239+
unset
240+
["c"]=>
241+
unset
236242
["d":protected]=>
237243
string(10) "Original d"
238244
["e":"C":private]=>
@@ -241,7 +247,13 @@ object(C)#%d (2) {
241247

242248
Removing properties from an object, using &$value.
243249
string(10) "Original a"
244-
object(C)#%d (2) {
250+
object(C)#%d (5) {
251+
["a"]=>
252+
unset
253+
["b"]=>
254+
unset
255+
["c"]=>
256+
unset
245257
["d":protected]=>
246258
string(10) "Original d"
247259
["e":"C":private]=>

tests/lang/foreachLoopObjects.004.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@ string(10) "Original d"
4141

4242
Warning: Undefined property: C::$b in %s on line %d
4343
string(10) "Original e"
44-
object(C)#%d (4) {
44+
object(C)#%d (5) {
4545
["a"]=>
4646
string(10) "Original a"
47+
["b"]=>
48+
unset
4749
["c"]=>
4850
string(10) "Original c"
4951
["d"]=>

tests/lang/foreachLoopObjects.005.phpt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@ string(10) "Original a"
4848
string(10) "Original b"
4949
string(10) "Original d"
5050
string(10) "Original e"
51-
object(C)#%d (4) {
51+
object(C)#%d (5) {
5252
["a"]=>
5353
string(10) "Original a"
5454
["b"]=>
5555
string(10) "Original b"
56+
["c"]=>
57+
unset
5658
["d"]=>
5759
string(10) "Original d"
5860
["e"]=>
@@ -65,7 +67,9 @@ string(10) "Original b"
6567
string(10) "Original c"
6668
string(10) "Original d"
6769
string(10) "Original e"
68-
object(C)#%d (4) {
70+
object(C)#%d (5) {
71+
["a"]=>
72+
unset
6973
["b"]=>
7074
string(10) "Original b"
7175
["c"]=>

0 commit comments

Comments
 (0)