@@ -4,12 +4,17 @@ Bug #60362: non-existent sub-sub keys should not have values
4
4
<?php
5
5
$ arr = array ('exists ' => 'foz ' );
6
6
7
- if (isset ($ arr ['exists ' ]['non_existent ' ])) {
8
- echo "sub-key 'non_existent' is set: " ;
9
- var_dump ($ arr ['exists ' ]['non_existent ' ]);
10
- } else {
11
- echo "sub-key 'non_existent' is not set. \n" ;
7
+ try {
8
+ if (isset ($ arr ['exists ' ]['non_existent ' ])) {
9
+ echo "sub-key 'non_existent' is set: " ;
10
+ var_dump ($ arr ['exists ' ]['non_existent ' ]);
11
+ } else {
12
+ echo "sub-key 'non_existent' is not set. \n" ;
13
+ }
14
+ } catch (\TypeError $ e ) {
15
+ echo $ e ->getMessage (), \PHP_EOL ;
12
16
}
17
+
13
18
if (isset ($ arr ['exists ' ][1 ])) {
14
19
echo "sub-key 1 is set: " ;
15
20
var_dump ($ arr ['exists ' ][1 ]);
@@ -18,11 +23,15 @@ if (isset($arr['exists'][1])) {
18
23
}
19
24
20
25
echo "------------------- \n" ;
21
- if (isset ($ arr ['exists ' ]['non_existent ' ]['sub_sub ' ])) {
22
- echo "sub-key 'sub_sub' is set: " ;
23
- var_dump ($ arr ['exists ' ]['non_existent ' ]['sub_sub ' ]);
24
- } else {
25
- echo "sub-sub-key 'sub_sub' is not set. \n" ;
26
+ try {
27
+ if (isset ($ arr ['exists ' ]['non_existent ' ]['sub_sub ' ])) {
28
+ echo "sub-key 'sub_sub' is set: " ;
29
+ var_dump ($ arr ['exists ' ]['non_existent ' ]['sub_sub ' ]);
30
+ } else {
31
+ echo "sub-sub-key 'sub_sub' is not set. \n" ;
32
+ }
33
+ } catch (\TypeError $ e ) {
34
+ echo $ e ->getMessage (), \PHP_EOL ;
26
35
}
27
36
if (isset ($ arr ['exists ' ][1 ][0 ])) {
28
37
echo "sub-sub-key 0 is set: " ;
@@ -32,11 +41,15 @@ if (isset($arr['exists'][1][0])) {
32
41
}
33
42
34
43
echo "------------------- \n" ;
35
- if (empty ($ arr ['exists ' ]['non_existent ' ])) {
36
- echo "sub-key 'non_existent' is empty. \n" ;
37
- } else {
38
- echo "sub-key 'non_existent' is not empty: " ;
39
- var_dump ($ arr ['exists ' ]['non_existent ' ]);
44
+ try {
45
+ if (empty ($ arr ['exists ' ]['non_existent ' ])) {
46
+ echo "sub-key 'non_existent' is empty. \n" ;
47
+ } else {
48
+ echo "sub-key 'non_existent' is not empty: " ;
49
+ var_dump ($ arr ['exists ' ]['non_existent ' ]);
50
+ }
51
+ } catch (\TypeError $ e ) {
52
+ echo $ e ->getMessage (), \PHP_EOL ;
40
53
}
41
54
if (empty ($ arr ['exists ' ][1 ])) {
42
55
echo "sub-key 1 is empty. \n" ;
@@ -46,11 +59,15 @@ if (empty($arr['exists'][1])) {
46
59
}
47
60
48
61
echo "------------------- \n" ;
49
- if (empty ($ arr ['exists ' ]['non_existent ' ]['sub_sub ' ])) {
50
- echo "sub-sub-key 'sub_sub' is empty. \n" ;
51
- } else {
52
- echo "sub-sub-key 'sub_sub' is not empty: " ;
53
- var_dump ($ arr ['exists ' ]['non_existent ' ]['sub_sub ' ]);
62
+ try {
63
+ if (empty ($ arr ['exists ' ]['non_existent ' ]['sub_sub ' ])) {
64
+ echo "sub-sub-key 'sub_sub' is empty. \n" ;
65
+ } else {
66
+ echo "sub-sub-key 'sub_sub' is not empty: " ;
67
+ var_dump ($ arr ['exists ' ]['non_existent ' ]['sub_sub ' ]);
68
+ }
69
+ } catch (\TypeError $ e ) {
70
+ echo $ e ->getMessage (), \PHP_EOL ;
54
71
}
55
72
if (empty ($ arr ['exists ' ][1 ][0 ])) {
56
73
echo "sub-sub-key 0 is empty. \n" ;
@@ -61,15 +78,15 @@ if (empty($arr['exists'][1][0])) {
61
78
echo "DONE " ;
62
79
?>
63
80
--EXPECT--
64
- sub-key 'non_existent' is not set.
81
+ Cannot access offset of type string on string
65
82
sub-key 1 is set: string(1) "o"
66
83
-------------------
67
- sub-sub-key 'sub_sub' is not set.
84
+ Cannot access offset of type string on string
68
85
sub-sub-key 0 is set: string(1) "o"
69
86
-------------------
70
- sub-key 'non_existent' is empty.
87
+ Cannot access offset of type string on string
71
88
sub-key 1 is not empty: string(1) "o"
72
89
-------------------
73
- sub-sub-key 'sub_sub' is empty.
90
+ Cannot access offset of type string on string
74
91
sub-sub-key 0 is not empty: string(1) "o"
75
92
DONE
0 commit comments