Skip to content

Commit d78c468

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

File tree

5 files changed

+25
-0
lines changed

5 files changed

+25
-0
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/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:
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
array_key_exists() with null key shows deprecation warning
3+
--FILE--
4+
<?php
5+
var_dump(array_key_exists(null, []));
6+
var_dump(array_key_exists(null, ["" => "value"]));
7+
var_dump(array_key_exists(null, ["key" => "value"]));
8+
?>
9+
--EXPECTF--
10+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
11+
bool(false)
12+
13+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
14+
bool(true)
15+
16+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
17+
bool(false)

0 commit comments

Comments
 (0)