xref: /PHP-8.1/Zend/tests/unset_non_array.phpt (revision 052af90b)
1--TEST--
2Unset on non-array
3--FILE--
4<?php
5
6unset($x[0]);
7
8$x = null;
9unset($x[0]);
10
11$x = false;
12unset($x[0]);
13
14$x = true;
15try {
16    unset($x[0]);
17} catch (Error $e) {
18    echo $e->getMessage(), "\n";
19}
20
21$x = 1;
22try {
23    unset($x[0]);
24} catch (Error $e) {
25    echo $e->getMessage(), "\n";
26}
27
28$x = 3.14;
29try {
30    unset($x[0]);
31} catch (Error $e) {
32    echo $e->getMessage(), "\n";
33}
34
35$x = "str";
36try {
37    unset($x[0]);
38} catch (Error $e) {
39    echo $e->getMessage(), "\n";
40}
41
42$x = new stdClass;
43try {
44    unset($x[0]);
45} catch (Error $e) {
46    echo $e->getMessage(), "\n";
47}
48
49// And now repeat the same with a nested offset.
50unset($x);
51
52unset($x[0][0]);
53
54$x = null;
55unset($x[0][0]);
56
57$x = false;
58unset($x[0][0]);
59
60$x = true;
61try {
62    unset($x[0][0]);
63} catch (Error $e) {
64    echo $e->getMessage(), "\n";
65}
66
67$x = 1;
68try {
69    unset($x[0][0]);
70} catch (Error $e) {
71    echo $e->getMessage(), "\n";
72}
73
74$x = 3.14;
75try {
76    unset($x[0][0]);
77} catch (Error $e) {
78    echo $e->getMessage(), "\n";
79}
80
81$x = "str";
82try {
83    unset($x[0][0]);
84} catch (Error $e) {
85    echo $e->getMessage(), "\n";
86}
87
88$x = new stdClass;
89try {
90    unset($x[0][0]);
91} catch (Error $e) {
92    echo $e->getMessage(), "\n";
93}
94
95?>
96--EXPECTF--
97Warning: Undefined variable $x in %s on line %d
98
99Deprecated: Automatic conversion of false to array is deprecated in %s
100Cannot unset offset in a non-array variable
101Cannot unset offset in a non-array variable
102Cannot unset offset in a non-array variable
103Cannot unset string offsets
104Cannot use object of type stdClass as array
105
106Warning: Undefined variable $x in %s on line %d
107
108Deprecated: Automatic conversion of false to array is deprecated in %s
109Cannot unset offset in a non-array variable
110Cannot unset offset in a non-array variable
111Cannot unset offset in a non-array variable
112Cannot unset string offsets
113Cannot use object of type stdClass as array
114