--- /dev/null
+--TEST--
+Bug #41351 (Invalid opcode with foreach ($a[] as $b)) - 2
+--FILE--
+<?php
+
+$a = array();
+
+foreach($a[]['test'] as $b) {
+}
+
+echo "Done\n";
+?>
+--EXPECTF--
+Fatal error: Cannot use [] for reading in %s on line %d
--- /dev/null
+--TEST--
+Bug #41351 (Invalid opcode with foreach ($a[] as $b)) - 3
+--FILE--
+<?php
+
+$a = array();
+
+foreach($a['test'][] as $b) {
+}
+
+echo "Done\n";
+?>
+--EXPECTF--
+Fatal error: Cannot use [] for reading in %s on line %d
/* Change "write context" into "read context" */
fetch->extended_value = 0; /* reset ZEND_FE_RESET_VARIABLE */
while (fetch != end) {
- (--fetch)->opcode -= 3; /* FETCH_W -> FETCH_R */
+ --fetch;
+ if (fetch->opcode == ZEND_FETCH_DIM_W && fetch->op2.op_type == IS_UNUSED) {
+ zend_error(E_COMPILE_ERROR, "Cannot use [] for reading");
+ }
+ fetch->opcode -= 3; /* FETCH_W -> FETCH_R */
}
/* prevent double SWITCH_FREE */
zend_stack_top(&CG(foreach_copy_stack), (void **) &foreach_copy);