Skip to content

Commit aca79f0

Browse files
committed
Add deprecation warning for array API
This is used by array_column(), the AST, and iterators
1 parent 8e227c3 commit aca79f0

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

Zend/tests/constexpr/constant_expressions_dynamic.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ var_dump(
4848
Warning: A non-numeric value encountered in %s on line %d
4949

5050
Deprecated: Implicit conversion from float 3.14 to int loses precision in %s on line %d
51+
52+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
5153
int(3)
5254
string(4) "1foo"
5355
bool(false)

Zend/zend_API.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2255,9 +2255,6 @@ ZEND_API zend_result array_set_zval_key(HashTable *ht, zval *key, zval *value) /
22552255
case IS_STRING:
22562256
result = zend_symtable_update(ht, Z_STR_P(key), value);
22572257
break;
2258-
case IS_NULL:
2259-
result = zend_hash_update(ht, ZSTR_EMPTY_ALLOC(), value);
2260-
break;
22612258
case IS_RESOURCE:
22622259
zend_use_resource_as_offset(key);
22632260
result = zend_hash_index_update(ht, Z_RES_HANDLE_P(key), value);
@@ -2274,6 +2271,13 @@ ZEND_API zend_result array_set_zval_key(HashTable *ht, zval *key, zval *value) /
22742271
case IS_DOUBLE:
22752272
result = zend_hash_index_update(ht, zend_dval_to_lval_safe(Z_DVAL_P(key)), value);
22762273
break;
2274+
case IS_NULL:
2275+
zend_error(E_DEPRECATED, "Using null as an array offset is deprecated, use an empty string instead");
2276+
if (UNEXPECTED(EG(exception))) {
2277+
return FAILURE;
2278+
}
2279+
result = zend_hash_update(ht, ZSTR_EMPTY_ALLOC(), value);
2280+
break;
22772281
default:
22782282
zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), key, BP_VAR_W);
22792283
result = NULL;

ext/spl/tests/iterator_to_array_nonscalar_keys.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,6 @@ try {
2121
?>
2222
--EXPECTF--
2323
Deprecated: Implicit conversion from float 2.5 to int loses precision in %s on line %d
24+
25+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
2426
Cannot access offset of type array on array

ext/standard/tests/array/bug68553.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ try {
3737
Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
3838

3939
Deprecated: Implicit conversion from float 7.38 to int loses precision in %s on line %d
40+
41+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
42+
43+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
4044
array(8) {
4145
[10]=>
4246
array(1) {

0 commit comments

Comments
 (0)