Skip to content

Commit 7055459

Browse files
committed
Fix phpGH-12380: JIT+private array property access inside closure accesses private property in child class
For private fields, the scope has to be taken into account, otherwise the property info may come from the wrong ce.
1 parent ae52f19 commit 7055459

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

ext/opcache/jit/zend_jit.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,11 @@ static zend_property_info* zend_get_known_property_info(const zend_op_array *op_
650650
return info;
651651
} else if (on_this) {
652652
if (ce == info->ce) {
653-
return info;
653+
if (ce == op_array->scope) {
654+
return info;
655+
} else {
656+
return NULL;
657+
}
654658
} else if ((info->flags & ZEND_ACC_PROTECTED)
655659
&& instanceof_function_slow(ce, info->ce)) {
656660
return info;

ext/opcache/tests/jit/gh12380.phpt

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
--TEST--
2+
GH-12380: JIT+private array property access inside closure accesses private property in child class
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.file_update_protection=0
7+
opcache.jit_buffer_size=1M
8+
opcache.protect_memory=1
9+
opcache.jit=tracing
10+
opcache.jit_hot_loop=1
11+
opcache.jit_hot_func=1
12+
opcache.jit_hot_return=1
13+
opcache.jit_hot_side_exit=1
14+
--EXTENSIONS--
15+
opcache
16+
--FILE--
17+
<?php
18+
19+
abstract class a
20+
{
21+
private int $v = 1;
22+
23+
public function test(): void
24+
{
25+
var_dump($this->v);
26+
(function (): void {
27+
var_dump($this->v);
28+
})();
29+
}
30+
}
31+
32+
final class b extends a {
33+
private int $v = 0;
34+
}
35+
$a = new b;
36+
37+
for ($i = 0; $i < 10; $i++) {
38+
$a->test();
39+
}
40+
41+
?>
42+
--EXPECT--
43+
int(1)
44+
int(1)
45+
int(1)
46+
int(1)
47+
int(1)
48+
int(1)
49+
int(1)
50+
int(1)
51+
int(1)
52+
int(1)
53+
int(1)
54+
int(1)
55+
int(1)
56+
int(1)
57+
int(1)
58+
int(1)
59+
int(1)
60+
int(1)
61+
int(1)
62+
int(1)

0 commit comments

Comments
 (0)