opline->extended_value &= ZEND_FETCH_TYPE_MASK;
opline->opcode -= 9;
} else {
+ if (opline->opcode == ZEND_FETCH_DIM_FUNC_ARG
+ && opline->op2_type == IS_UNUSED) {
+ /* FETCH_DIM_FUNC_ARG supports UNUSED op2, while FETCH_DIM_R does not.
+ * Performing the replacement would create an invalid opcode. */
+ break;
+ }
+
opline->extended_value &= ZEND_FETCH_TYPE_MASK;
opline->opcode -= 12;
}
--- /dev/null
+--TEST--
+Don't create FETCH_DIM_R with UNUSED op2
+--FILE--
+<?php
+
+// Order matters
+test($arr[]);
+function test($arg) {}
+
+?>
+--EXPECTF--
+Fatal error: Uncaught Error: Cannot use [] for reading in %s:%d
+Stack trace:
+#0 {main}
+ thrown in %s on line %d