Skip to content

Commit a5509da

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

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
@@ -2233,9 +2233,6 @@ ZEND_API zend_result array_set_zval_key(HashTable *ht, zval *key, zval *value) /
22332233
case IS_STRING:
22342234
result = zend_symtable_update(ht, Z_STR_P(key), value);
22352235
break;
2236-
case IS_NULL:
2237-
result = zend_hash_update(ht, ZSTR_EMPTY_ALLOC(), value);
2238-
break;
22392236
case IS_RESOURCE:
22402237
zend_use_resource_as_offset(key);
22412238
result = zend_hash_index_update(ht, Z_RES_HANDLE_P(key), value);
@@ -2252,6 +2249,13 @@ ZEND_API zend_result array_set_zval_key(HashTable *ht, zval *key, zval *value) /
22522249
case IS_DOUBLE:
22532250
result = zend_hash_index_update(ht, zend_dval_to_lval_safe(Z_DVAL_P(key)), value);
22542251
break;
2252+
case IS_NULL:
2253+
zend_error(E_DEPRECATED, "Using null as an array offset is deprecated, use an empty string instead");
2254+
if (UNEXPECTED(EG(exception))) {
2255+
return FAILURE;
2256+
}
2257+
result = zend_hash_update(ht, ZSTR_EMPTY_ALLOC(), value);
2258+
break;
22552259
default:
22562260
zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_ARRAY), key, BP_VAR_W);
22572261
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)