Skip to content

Commit 6b521a3

Browse files
Deprecate using null as an array offset and when calling array_key_exists()
1 parent c98b173 commit 6b521a3

File tree

9 files changed

+142
-27
lines changed

9 files changed

+142
-27
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ PHP NEWS
1212
error in PHP 9. (alexandre-daubois)
1313
. Fixed OSS-Fuzz #439125710 (Pipe cannot be used in write context).
1414
(nielsdos)
15+
. Using null as an array offset and when calling array_key_exists() is now
16+
deprecated. Use an emprty string instead. (alexandre-daubois)
1517

1618
- ODBC:
1719
. Remove ODBCVER and assume ODBC 3.5. (Calvin Buckley)

UPGRADING

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,9 @@ PHP 8.5 UPGRADE NOTES
440440
. Passing integers outside the interval [0, 255] to chr() is now deprecated.
441441
This is because a byte can only hold a value within this interval.
442442
RFC: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_passing_integers_outside_the_interval_0_255_to_chr
443+
. Using null as an array offset and when calling array_key_exists() is now
444+
deprecated. Use an empty string instead.
445+
RFC: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_using_values_null_as_an_array_offset_and_when_calling_array_key_exists
443446

444447
- XML:
445448
. The xml_parser_free() function has been deprecated, as XMLParser objects

Zend/tests/nullsafe_operator/013.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,7 @@ array(1) {
7272
[0]=>
7373
string(3) "foo"
7474
}
75+
76+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
7577
bool(false)
7678
string(74) "array_key_exists(): Argument #2 ($array) must be of type array, null given"

Zend/zend_execute.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3324,6 +3324,8 @@ static zend_never_inline bool ZEND_FASTCALL zend_array_key_exists_fast(HashTable
33243324
} else if (Z_TYPE_P(key) <= IS_NULL) {
33253325
if (UNEXPECTED(Z_TYPE_P(key) == IS_UNDEF)) {
33263326
ZVAL_UNDEFINED_OP1();
3327+
} else if (Z_TYPE_P(key) == IS_NULL) {
3328+
zend_error(E_DEPRECATED, "Using null as an array offset is deprecated, use an empty string instead");
33273329
}
33283330
str = ZSTR_EMPTY_ALLOC();
33293331
goto str_key;

ext/standard/array.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6981,6 +6981,7 @@ PHP_FUNCTION(array_key_exists)
69816981
RETVAL_BOOL(zend_hash_index_exists(ht, Z_LVAL_P(key)));
69826982
break;
69836983
case IS_NULL:
6984+
zend_error(E_DEPRECATED, "Using null as an array offset is deprecated, use an empty string instead");
69846985
RETVAL_BOOL(zend_hash_exists(ht, ZSTR_EMPTY_ALLOC()));
69856986
break;
69866987
case IS_DOUBLE:

ext/standard/tests/array/array_key_exists.phpt

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ try {
8282

8383
echo "Done\n";
8484
?>
85-
--EXPECT--
85+
--EXPECTF--
8686
*** Testing basic functionalities ***
8787
-- Iteration 1 --
8888
bool(true)
@@ -104,55 +104,83 @@ bool(true)
104104
** Variation loop 1 **
105105
-- Iteration 1 --
106106
bool(false)
107+
108+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
107109
bool(false)
110+
111+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
108112
bool(false)
109113
bool(false)
110114
bool(false)
111115
bool(false)
112116
bool(true)
113117
-- Iteration 2 --
114118
bool(false)
119+
120+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
115121
bool(false)
122+
123+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
116124
bool(false)
117125
bool(false)
118126
bool(false)
119127
bool(false)
120128
bool(true)
121129
-- Iteration 3 --
122130
bool(false)
131+
132+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
123133
bool(false)
134+
135+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
124136
bool(false)
125137
bool(false)
126138
bool(false)
127139
bool(false)
128140
bool(true)
129141
-- Iteration 4 --
130142
bool(false)
143+
144+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
131145
bool(false)
146+
147+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
132148
bool(false)
133149
bool(false)
134150
bool(false)
135151
bool(false)
136152
bool(true)
137153
-- Iteration 5 --
138154
bool(false)
155+
156+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
139157
bool(false)
158+
159+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
140160
bool(false)
141161
bool(false)
142162
bool(false)
143163
bool(false)
144164
bool(false)
145165
-- Iteration 6 --
146166
bool(false)
167+
168+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
147169
bool(false)
170+
171+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
148172
bool(false)
149173
bool(false)
150174
bool(false)
151175
bool(false)
152176
bool(false)
153177
-- Iteration 7 --
154178
bool(false)
179+
180+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
155181
bool(false)
182+
183+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
156184
bool(false)
157185
bool(false)
158186
bool(false)
@@ -162,39 +190,59 @@ bool(true)
162190
** Variation loop 2 **
163191
-- Iteration 1 --
164192
bool(false)
193+
194+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
165195
bool(false)
196+
197+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
166198
bool(false)
167199
bool(false)
168200
bool(false)
169201
bool(false)
170202
bool(false)
171203
-- Iteration 2 --
172204
bool(false)
205+
206+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
173207
bool(false)
208+
209+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
174210
bool(false)
175211
bool(false)
176212
bool(false)
177213
bool(false)
178214
bool(false)
179215
-- Iteration 3 --
180216
bool(false)
217+
218+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
181219
bool(false)
220+
221+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
182222
bool(false)
183223
bool(false)
184224
bool(false)
185225
bool(false)
186226
bool(true)
187227
-- Iteration 4 --
188228
bool(true)
229+
230+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
189231
bool(true)
232+
233+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
190234
bool(true)
191235
bool(false)
192236
bool(true)
193237
bool(false)
194238
bool(true)
195239
-- Iteration 5 --
196240
bool(false)
241+
242+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
197243
bool(false)
244+
245+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
198246
bool(false)
199247
bool(false)
200248
bool(false)

ext/standard/tests/array/array_key_exists_variation1.phpt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,13 @@ bool(false)
105105
bool(false)
106106

107107
-- Iteration 5 --
108+
109+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
108110
bool(false)
109111

110112
-- Iteration 6 --
113+
114+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
111115
bool(false)
112116

113117
-- Iteration 7 --
@@ -144,9 +148,13 @@ bool(true)
144148
Cannot access offset of type classA on array
145149

146150
-- Iteration 18 --
151+
152+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
147153
bool(false)
148154

149155
-- Iteration 19 --
156+
157+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
150158
bool(false)
151159

152160
-- Iteration 20 --

ext/standard/tests/array/array_key_exists_variation6.phpt

Lines changed: 73 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,54 +36,102 @@ foreach($array as $name => $input) {
3636

3737
echo "Done";
3838
?>
39-
--EXPECT--
39+
--EXPECTF--
4040
*** Testing array_key_exists() : usage variations ***
4141

4242
-- Key in $search array is : null --
43-
Iteration 1: bool(true)
44-
Iteration 2: bool(true)
43+
Iteration 1:
44+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
45+
bool(true)
46+
Iteration 2:
47+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
48+
bool(true)
4549
Iteration 3: bool(true)
4650
Iteration 4: bool(true)
47-
Iteration 5: bool(true)
48-
Iteration 6: bool(true)
51+
Iteration 5:
52+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
53+
bool(true)
54+
Iteration 6:
55+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
56+
bool(true)
4957

5058
-- Key in $search array is : NULL --
51-
Iteration 1: bool(true)
52-
Iteration 2: bool(true)
59+
Iteration 1:
60+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
61+
bool(true)
62+
Iteration 2:
63+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
64+
bool(true)
5365
Iteration 3: bool(true)
5466
Iteration 4: bool(true)
55-
Iteration 5: bool(true)
56-
Iteration 6: bool(true)
67+
Iteration 5:
68+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
69+
bool(true)
70+
Iteration 6:
71+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
72+
bool(true)
5773

5874
-- Key in $search array is : empty single quoted string --
59-
Iteration 1: bool(true)
60-
Iteration 2: bool(true)
75+
Iteration 1:
76+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
77+
bool(true)
78+
Iteration 2:
79+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
80+
bool(true)
6181
Iteration 3: bool(true)
6282
Iteration 4: bool(true)
63-
Iteration 5: bool(true)
64-
Iteration 6: bool(true)
83+
Iteration 5:
84+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
85+
bool(true)
86+
Iteration 6:
87+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
88+
bool(true)
6589

6690
-- Key in $search array is : empty double quoted string --
67-
Iteration 1: bool(true)
68-
Iteration 2: bool(true)
91+
Iteration 1:
92+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
93+
bool(true)
94+
Iteration 2:
95+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
96+
bool(true)
6997
Iteration 3: bool(true)
7098
Iteration 4: bool(true)
71-
Iteration 5: bool(true)
72-
Iteration 6: bool(true)
99+
Iteration 5:
100+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
101+
bool(true)
102+
Iteration 6:
103+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
104+
bool(true)
73105

74106
-- Key in $search array is : undefined variable --
75-
Iteration 1: bool(true)
76-
Iteration 2: bool(true)
107+
Iteration 1:
108+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
109+
bool(true)
110+
Iteration 2:
111+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
112+
bool(true)
77113
Iteration 3: bool(true)
78114
Iteration 4: bool(true)
79-
Iteration 5: bool(true)
80-
Iteration 6: bool(true)
115+
Iteration 5:
116+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
117+
bool(true)
118+
Iteration 6:
119+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
120+
bool(true)
81121

82122
-- Key in $search array is : unset variable --
83-
Iteration 1: bool(true)
84-
Iteration 2: bool(true)
123+
Iteration 1:
124+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
125+
bool(true)
126+
Iteration 2:
127+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
128+
bool(true)
85129
Iteration 3: bool(true)
86130
Iteration 4: bool(true)
87-
Iteration 5: bool(true)
88-
Iteration 6: bool(true)
131+
Iteration 5:
132+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
133+
bool(true)
134+
Iteration 6:
135+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
136+
bool(true)
89137
Done

ext/standard/tests/array/bug20865.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ Bug #20865 (array_key_exists and NULL key)
77

88
var_dump(array_key_exists(NULL, $ta));
99
?>
10-
--EXPECT--
10+
--EXPECTF--
11+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
1112
bool(true)

0 commit comments

Comments
 (0)