diff --git a/Zend/tests/foreach/foreach_list_002.phpt b/Zend/tests/foreach/foreach_list_002.phpt index 1c693651fdc4b..5a8f97f919443 100644 --- a/Zend/tests/foreach/foreach_list_002.phpt +++ b/Zend/tests/foreach/foreach_list_002.phpt @@ -17,6 +17,8 @@ foreach($array as list(, $a)) { --EXPECT-- int(1) int(3) -string(1) "b" +string(1) + +Warning: Cannot use string as array in %s on line %d NULL NULL diff --git a/Zend/tests/list/bug39304.phpt b/Zend/tests/list/bug39304.phpt index a5422d2f4f316..353baa5df01df 100644 --- a/Zend/tests/list/bug39304.phpt +++ b/Zend/tests/list/bug39304.phpt @@ -8,5 +8,9 @@ Bug #39304 (Segmentation fault with list unpacking of string offset) ?> --EXPECTF-- Warning: Uninitialized string offset 0 in %s on line %d + +Warning: Cannot use string as array in %s on line %d + +Warning: Cannot use string as array in %s on line %d NULL NULL diff --git a/Zend/tests/list/destruct_bool.phpt b/Zend/tests/list/destruct_bool.phpt new file mode 100644 index 0000000000000..7553811220c99 --- /dev/null +++ b/Zend/tests/list/destruct_bool.phpt @@ -0,0 +1,18 @@ +--TEST-- +Destructuring with list() a value of type bool +--FILE-- + +--EXPECTF-- +Warning: Cannot use bool as array in %s on line %d + +Warning: Cannot use bool as array in %s on line %d +NULL +NULL diff --git a/Zend/tests/list/destruct_float.phpt b/Zend/tests/list/destruct_float.phpt new file mode 100644 index 0000000000000..6423a5b5668a4 --- /dev/null +++ b/Zend/tests/list/destruct_float.phpt @@ -0,0 +1,18 @@ +--TEST-- +Destructuring with list() a value of type float +--FILE-- + +--EXPECTF-- +Warning: Cannot use float as array in %s on line %d + +Warning: Cannot use float as array in %s on line %d +NULL +NULL diff --git a/Zend/tests/list/destruct_int.phpt b/Zend/tests/list/destruct_int.phpt new file mode 100644 index 0000000000000..e232ecb73982a --- /dev/null +++ b/Zend/tests/list/destruct_int.phpt @@ -0,0 +1,18 @@ +--TEST-- +Destructuring with list() a value of type int +--FILE-- + +--EXPECTF-- +Warning: Cannot use int as array in %s on line %d + +Warning: Cannot use int as array in %s on line %d +NULL +NULL diff --git a/Zend/tests/list/destruct_null.phpt b/Zend/tests/list/destruct_null.phpt new file mode 100644 index 0000000000000..e89de45a28e83 --- /dev/null +++ b/Zend/tests/list/destruct_null.phpt @@ -0,0 +1,12 @@ +--TEST-- +Destructuring with list() a value of type null +--FILE-- + +--EXPECT-- +NULL diff --git a/Zend/tests/list/destruct_object_not_ArrayAccess.phpt b/Zend/tests/list/destruct_object_not_ArrayAccess.phpt new file mode 100644 index 0000000000000..097c2cd2def3e --- /dev/null +++ b/Zend/tests/list/destruct_object_not_ArrayAccess.phpt @@ -0,0 +1,17 @@ +--TEST-- +Destructuring with list() a value of type object (that does not implement ArrayAccess) +--FILE-- + +--EXPECTF-- +Fatal error: Uncaught Error: Cannot use object of type stdClass as array in %s:%d +Stack trace: +#0 {main} + thrown in %s on line %d diff --git a/Zend/tests/list/destruct_resource.phpt b/Zend/tests/list/destruct_resource.phpt new file mode 100644 index 0000000000000..8e5576767fe11 --- /dev/null +++ b/Zend/tests/list/destruct_resource.phpt @@ -0,0 +1,18 @@ +--TEST-- +Destructuring with list() a value of type resource +--FILE-- + +--EXPECTF-- +Warning: Cannot use resource as array in %s on line %d + +Warning: Cannot use resource as array in %s on line %d +NULL +NULL diff --git a/Zend/tests/list/destruct_string.phpt b/Zend/tests/list/destruct_string.phpt new file mode 100644 index 0000000000000..b2ea88c65a6cf --- /dev/null +++ b/Zend/tests/list/destruct_string.phpt @@ -0,0 +1,21 @@ +--TEST-- +Destructuring with list() a value of type string +--FILE-- + +--EXPECTF-- +Warning: Cannot use string as array in %s on line %d + +Warning: Cannot use string as array in %s on line %d + +Warning: Cannot use string as array in %s on line %d +NULL +NULL +NULL diff --git a/Zend/tests/list/list_003.phpt b/Zend/tests/list/list_003.phpt deleted file mode 100644 index 4a509f6a828b4..0000000000000 --- a/Zend/tests/list/list_003.phpt +++ /dev/null @@ -1,24 +0,0 @@ ---TEST-- -list() with non-array ---FILE-- - ---EXPECT-- -NULL -NULL -NULL -NULL -NULL diff --git a/Zend/tests/list/list_005.phpt b/Zend/tests/list/list_005.phpt deleted file mode 100644 index 7dc3bf6fa36a6..0000000000000 --- a/Zend/tests/list/list_005.phpt +++ /dev/null @@ -1,50 +0,0 @@ ---TEST-- -Testing list() with several variables ---FILE-- - ---EXPECTF-- -NULL -NULL -NULL ----- -NULL -NULL -NULL ----- - -Fatal error: Uncaught Error: Cannot use object of type stdClass as array in %s:%d -Stack trace: -#0 {main} - thrown in %s on line %d diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 3908299a41c3f..701a5e89a411e 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -3005,7 +3005,7 @@ static zend_never_inline void ZEND_FASTCALL zend_fetch_dimension_address_UNSET(z zend_fetch_dimension_address(result, container_ptr, dim, dim_type, BP_VAR_UNSET EXECUTE_DATA_CC); } -static zend_always_inline void zend_fetch_dimension_address_read(zval *result, zval *container, zval *dim, int dim_type, int type, bool is_list, int slow EXECUTE_DATA_DC) +static zend_always_inline void zend_fetch_dimension_address_read(zval *result, zval *container, zval *dim, int dim_type, int type, bool is_list, bool slow EXECUTE_DATA_DC) { zval *retval; @@ -3143,6 +3143,9 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z if (ZEND_CONST_COND(dim_type == IS_CV, 1) && UNEXPECTED(Z_TYPE_P(dim) == IS_UNDEF)) { ZVAL_UNDEFINED_OP2(); } + if (is_list && Z_TYPE_P(container) > IS_NULL) { + zend_error(E_WARNING, "Cannot use %s as array", zend_zval_type_name(container)); + } if (!is_list && type != BP_VAR_IS) { zend_error(E_WARNING, "Trying to access array offset on %s", zend_zval_value_name(container)); diff --git a/ext/opcache/tests/jit/fetch_list_r_001.phpt b/ext/opcache/tests/jit/fetch_list_r_001.phpt index ec93b305ffafa..f5f0fee4084e5 100644 --- a/ext/opcache/tests/jit/fetch_list_r_001.phpt +++ b/ext/opcache/tests/jit/fetch_list_r_001.phpt @@ -13,5 +13,6 @@ function test() { } test(); ?> ---EXPECT-- +--EXPECTF-- +Warning: Cannot use string as array in %s on line %d NULL diff --git a/ext/opcache/tests/opt/block_pass_003.phpt b/ext/opcache/tests/opt/block_pass_003.phpt index 25d32e1e4d70e..0d97ee19127d2 100644 --- a/ext/opcache/tests/opt/block_pass_003.phpt +++ b/ext/opcache/tests/opt/block_pass_003.phpt @@ -1,5 +1,5 @@ --TEST-- -Block Pass 003: Inorrect constant substitution in FETCH_LIST_R +Block Pass 003: Incorrect constant substitution in FETCH_LIST_R --INI-- opcache.enable=1 opcache.enable_cli=1 @@ -16,5 +16,8 @@ function test() { test(); ?> DONE ---EXPECT-- +--EXPECTF-- +Warning: Cannot use int as array in %s on line %d + +Warning: Cannot use int as array in %s on line %d DONE diff --git a/tests/lang/engine_assignExecutionOrder_002.phpt b/tests/lang/engine_assignExecutionOrder_002.phpt index 956e3f9066d3d..a70cd5bafc8f2 100644 --- a/tests/lang/engine_assignExecutionOrder_002.phpt +++ b/tests/lang/engine_assignExecutionOrder_002.phpt @@ -116,6 +116,10 @@ array(3) { int(3000) } L=100 M=200 N=300 + +Warning: Cannot use int as array in %s on line %d + +Warning: Cannot use int as array in %s on line %d O= and P= 10 20 40 50 60 70 80