Skip to content

Commit 09b582b

Browse files
committed
Fix GH-20194 without opcache
1 parent 23162d8 commit 09b582b

File tree

4 files changed

+184
-38
lines changed

4 files changed

+184
-38
lines changed

Zend/tests/offsets/gh20194.phpt

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

Zend/zend_compile.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10287,9 +10287,7 @@ static bool zend_try_ct_eval_array(zval *result, zend_ast *ast) /* {{{ */
1028710287
zend_long lval = zend_dval_to_lval_silent(Z_DVAL_P(key));
1028810288
/* Incompatible float will generate an error, leave this to run-time */
1028910289
if (!zend_is_long_compatible(Z_DVAL_P(key), lval)) {
10290-
zval_ptr_dtor_nogc(value);
10291-
zval_ptr_dtor(result);
10292-
return 0;
10290+
goto fail;
1029310291
}
1029410292
zend_hash_index_update(Z_ARRVAL_P(result), lval, value);
1029510293
break;
@@ -10301,13 +10299,14 @@ static bool zend_try_ct_eval_array(zval *result, zend_ast *ast) /* {{{ */
1030110299
zend_hash_index_update(Z_ARRVAL_P(result), 1, value);
1030210300
break;
1030310301
case IS_NULL:
10304-
zend_hash_update(Z_ARRVAL_P(result), ZSTR_EMPTY_ALLOC(), value);
10305-
break;
10302+
/* Null key will generate a warning at run-time. */
10303+
goto fail;
1030610304
default:
1030710305
zend_error_noreturn(E_COMPILE_ERROR, "Illegal offset type");
1030810306
break;
1030910307
}
1031010308
} else if (!zend_hash_next_index_insert(Z_ARRVAL_P(result), value)) {
10309+
fail:
1031110310
zval_ptr_dtor_nogc(value);
1031210311
zval_ptr_dtor(result);
1031310312
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)