Skip to content

Commit fb68387

Browse files
committed
Fix GH-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. Closes GH-12381.
1 parent 36b2c5d commit fb68387

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ PHP NEWS
4242

4343
- Opcache:
4444
. Fixed opcache_invalidate() on deleted file. (mikhainin)
45+
. Fixed bug GH-12380 (JIT+private array property access inside closure
46+
accesses private property in child class). (nielsdos)
4547

4648
- PCRE:
4749
. Fixed bug GH-11956 (Backport upstream fix, PCRE regular expressions with

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)