Fix compact_literals of INIT_METHOD_CALL with CONST op1
authorNikita Popov <nikita.ppv@gmail.com>
Sat, 15 Apr 2017 10:35:09 +0000 (12:35 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Sat, 15 Apr 2017 10:35:09 +0000 (12:35 +0200)
ext/opcache/Optimizer/compact_literals.c
ext/opcache/tests/method_call_on_literal.phpt [new file with mode: 0644]

index 0637d77f2183028a599bd0a305a7002f4e8a0bfb..f417bef5fb326e73e88e1cfcb13cb2bf89b7862d 100644 (file)
@@ -146,6 +146,9 @@ void zend_optimizer_compact_literals(zend_op_array *op_array, zend_optimizer_ctx
                                        LITERAL_INFO(opline->op2.constant, LITERAL_FUNC, 1, 1, 3);
                                        break;
                                case ZEND_INIT_METHOD_CALL:
+                                       if (ZEND_OP1_TYPE(opline) == IS_CONST) {
+                                               LITERAL_INFO(opline->op1.constant, LITERAL_VALUE, 1, 0, 1);
+                                       }
                                        if (ZEND_OP2_TYPE(opline) == IS_CONST) {
                                                optimizer_literal_obj_info(
                                                        info,
diff --git a/ext/opcache/tests/method_call_on_literal.phpt b/ext/opcache/tests/method_call_on_literal.phpt
new file mode 100644 (file)
index 0000000..bf89caa
--- /dev/null
@@ -0,0 +1,14 @@
+--TEST--
+Literal compaction should take method calls on literals into account
+--FILE--
+<?php
+
+try {
+    (42)->foo();
+} catch (Error $e) {
+    echo $e->getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+Call to a member function foo() on integer