Skip to content

Commit c3667a5

Browse files
committed
Disable inlining for $this->foo(), because $this may be used not in object context
1 parent 5ae07dc commit c3667a5

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

ext/opcache/Optimizer/optimize_func_calls.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ static void zend_try_inline_call(zend_op_array *op_array, zend_op *fcall, zend_o
9898

9999
if (ret_opline->op1_type == IS_CONST) {
100100

101+
if (fcall->opcode == ZEND_INIT_METHOD_CALL && fcall->op1_type == IS_UNUSED) {
102+
/* TODO: we can't inlne methods, because $this may be used
103+
* not in class context ???
104+
*/
105+
return;
106+
}
101107
if (fcall->extended_value < func->op_array.num_args) {
102108
/* don't inline funcions with named constants in default arguments */
103109
uint32_t n = fcall->extended_value;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
Pass result of inlined function by reference
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
--SKIPIF--
8+
<?php require_once('skipif.inc'); ?>
9+
--FILE--
10+
<?php
11+
class Foo {
12+
private function getConst() {
13+
return 42;
14+
}
15+
public function test() {
16+
var_dump($this->getConst());
17+
}
18+
}
19+
20+
Foo::test();
21+
?>
22+
--EXPECTF--
23+
Deprecated: Non-static method Foo::test() should not be called statically in %swrong_inlining_002.php on line 11
24+
25+
Fatal error: Uncaught Error: Using $this when not in object context in %swrong_inlining_002.php:7
26+
Stack trace:
27+
#0 %swrong_inlining_002.php(11): Foo::test()
28+
#1 {main}
29+
thrown in %swrong_inlining_002.php on line 7

0 commit comments

Comments
 (0)