Skip to content

Commit dfb44f6

Browse files
committed
Fix GH-20194 without opcache
1 parent c2523ed commit dfb44f6

File tree

4 files changed

+186
-38
lines changed

4 files changed

+186
-38
lines changed

Zend/tests/offsets/gh20194.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
GH-20194: Using null as an array offset does not emit deprecation when resolved at compile time
3+
--INI--
4+
opcache.opt_debug_level=0x20000
5+
--FILE--
6+
<?php
7+
8+
$a = [null => 1];
9+
10+
echo $a[null];
11+
12+
?>
13+
--EXPECTF--
14+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
15+
16+
Deprecated: Using null as an array offset is deprecated, use an empty string instead in %s on line %d
17+
1

Zend/zend_compile.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10175,9 +10175,7 @@ static bool zend_try_ct_eval_array(zval *result, zend_ast *ast) /* {{{ */
1017510175
zend_long lval = zend_dval_to_lval_silent(Z_DVAL_P(key));
1017610176
/* Incompatible float will generate an error, leave this to run-time */
1017710177
if (!zend_is_long_compatible(Z_DVAL_P(key), lval)) {
10178-
zval_ptr_dtor_nogc(value);
10179-
zval_ptr_dtor(result);
10180-
return 0;
10178+
goto fail;
1018110179
}
1018210180
zend_hash_index_update(Z_ARRVAL_P(result), lval, value);
1018310181
break;
@@ -10189,13 +10187,14 @@ static bool zend_try_ct_eval_array(zval *result, zend_ast *ast) /* {{{ */
1018910187
zend_hash_index_update(Z_ARRVAL_P(result), 1, value);
1019010188
break;
1019110189
case IS_NULL:
10192-
zend_hash_update(Z_ARRVAL_P(result), ZSTR_EMPTY_ALLOC(), value);
10193-
break;
10190+
/* Null key will generate a warning at run-time. */
10191+
goto fail;
1019410192
default:
1019510193
zend_error_noreturn(E_COMPILE_ERROR, "Illegal offset type");
1019610194
break;
1019710195
}
1019810196
} else if (!zend_hash_next_index_insert(Z_ARRVAL_P(result), value)) {
10197+
fail:
1019910198
zval_ptr_dtor_nogc(value);
1020010199
zval_ptr_dtor(result);
1020110200
return 0;

Zend/zend_vm_def.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6278,7 +6278,11 @@ ZEND_VM_C_LABEL(num_index):
62786278
} else if ((OP2_TYPE & (IS_VAR|IS_CV)) && EXPECTED(Z_TYPE_P(offset) == IS_REFERENCE)) {
62796279
offset = Z_REFVAL_P(offset);
62806280
ZEND_VM_C_GOTO(add_again);
6281-
} else if (Z_TYPE_P(offset) == IS_NULL) {
6281+
} else if (UNEXPECTED(Z_TYPE_P(offset) == IS_NULL)) {
6282+
zend_error(E_DEPRECATED, "Using null as an array offset is deprecated, use an empty string instead");
6283+
if (UNEXPECTED(EG(exception))) {
6284+
HANDLE_EXCEPTION();
6285+
}
62826286
str = ZSTR_EMPTY_ALLOC();
62836287
ZEND_VM_C_GOTO(str_index);
62846288
} else if (Z_TYPE_P(offset) == IS_DOUBLE) {

0 commit comments

Comments
 (0)