com php-src: Disable inlining for $this->foo(), because $this may be used not in object context: ext/opcache/Optimizer/optimize_func_ calls.c
ext/opcache/tests/wrong_inlining_002.ph pt
| From: | Dmitry Stogov | Date: | Thu, 30 Jun 2016 18:03:08 +0000 |
| Subject: | com php-src: Disable inlining for $this->foo(), because $this may be used not in object context: ext/opcache/Optimizer/optimize_func_ calls.c ext/opcache/tests/wrong_inlining_002.ph pt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-92722@lists.php.net to get a copy of this message | ||
Commit: c3667a5eed098cc106351ec032306a149509dfa3
Author: Dmitry Stogov <dmitry@zend.com> Thu, 30 Jun 2016 21:03:08 +0300
Parents: 5ae07dc34ac7582c6ea5fdc5f24129a05ac9c78a
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=c3667a5eed098cc106351ec032306a149509dfa3
Log:
Disable inlining for $this->foo(), because $this may be used not in object context
Changed paths:
M ext/opcache/Optimizer/optimize_func_calls.c
A ext/opcache/tests/wrong_inlining_002.phpt
Diff:
diff --git a/ext/opcache/Optimizer/optimize_func_calls.c
b/ext/opcache/Optimizer/optimize_func_calls.c
index bf84a7a3...0d5e4d7 100644
--- a/ext/opcache/Optimizer/optimize_func_calls.c
+++ b/ext/opcache/Optimizer/optimize_func_calls.c
@@ -98,6 +98,12 @@ static void zend_try_inline_call(zend_op_array *op_array, zend_op *fcall, zend_o
if (ret_opline->op1_type == IS_CONST) {
+ if (fcall->opcode == ZEND_INIT_METHOD_CALL && fcall->op1_type == IS_UNUSED) {
+ /* TODO: we can't inlne methods, because $this may be used
+ * not in class context ???
+ */
+ return;
+ }
if (fcall->extended_value < func->op_array.num_args) {
/* don't inline funcions with named constants in default arguments */
uint32_t n = fcall->extended_value;
diff --git a/ext/opcache/tests/wrong_inlining_002.phpt b/ext/opcache/tests/wrong_inlining_002.phpt
new file mode 100644
index 0000000..e132f98
--- /dev/null
+++ b/ext/opcache/tests/wrong_inlining_002.phpt
@@ -0,0 +1,29 @@
+--TEST--
+Pass result of inlined function by reference
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.optimization_level=-1
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+class Foo {
+ private function getConst() {
+ return 42;
+ }
+ public function test() {
+ var_dump($this->getConst());
+ }
+}
+
+Foo::test();
+?>
+--EXPECTF--
+Deprecated: Non-static method Foo::test() should not be called statically in
%swrong_inlining_002.php on line 11
+
+Fatal error: Uncaught Error: Using $this when not in object context in %swrong_inlining_002.php:7
+Stack trace:
+#0 %swrong_inlining_002.php(11): Foo::test()
+#1 {main}
+ thrown in %swrong_inlining_002.php on line 7