Skip to content

Commit 2cf3a17

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: NEWS Fix property hook escape analysis causing misoptimization Fix __isset escape analysis causing misoptimization
2 parents 3014659 + 3b3f5dd commit 2cf3a17

4 files changed

Lines changed: 111 additions & 1 deletion

File tree

‎NEWS‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ PHP NEWS
8787
proxy objects instead of forwarding to the real instance). (lisachenko)
8888
. Fixed bug GH-23679 (Tracing JIT writes a parent private property into a
8989
child's shadowing public property). (Ilia Alshanetsky)
90-
. Fix incorrect DCE due to unsound escape analysis. (ndossche)
90+
. Fix multiple incorrect DCE due to unsound escape analysis. (ndossche,
91+
arnaud-lb)
9192

9293
- OpenSSL:
9394
. Fixed stream_socket_enable_crypto() leaving the socket non-blocking

‎Zend/Optimizer/escape_analysis.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ static bool is_allocation_def(zend_op_array *op_array, zend_ssa *ssa, int def, i
173173
&& !ce->destructor
174174
&& !ce->__get
175175
&& !ce->__set
176+
&& !ce->__isset
177+
&& !ce->num_hooked_props
176178
&& !(ce->ce_flags & forbidden_flags)
177179
&& (ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED)) {
178180
return 1;
@@ -242,6 +244,8 @@ static bool is_local_def(zend_op_array *op_array, zend_ssa *ssa, int def, int va
242244
&& !ce->destructor
243245
&& !ce->__get
244246
&& !ce->__set
247+
&& !ce->__isset
248+
&& !ce->num_hooked_props
245249
&& !ce->parent) {
246250
return 1;
247251
}

‎ext/opcache/tests/opt/dce_016.phpt‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
--TEST--
2+
DCE must not remove assignments to properties of an object escaping through __isset
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
opcache.file_update_protection=0
8+
--EXTENSIONS--
9+
opcache
10+
--FILE--
11+
<?php
12+
13+
class C {
14+
public $x = 0;
15+
function __isset($n) {
16+
global $g;
17+
$g = $this;
18+
return true;
19+
}
20+
}
21+
22+
function f() {
23+
$o = new C;
24+
isset($o->foo);
25+
$o->x = 42;
26+
}
27+
28+
f();
29+
var_dump($g->x);
30+
31+
#[AllowDynamicProperties]
32+
class F {
33+
function __isset($n) {
34+
$this->x = 2;
35+
return true;
36+
}
37+
}
38+
39+
function i() {
40+
$o = new F;
41+
$o->x = 1;
42+
isset($o->foo);
43+
var_dump($o->x);
44+
}
45+
i();
46+
47+
?>
48+
--EXPECT--
49+
int(42)
50+
int(2)

‎ext/opcache/tests/opt/dce_017.phpt‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
--TEST--
2+
DCE must not remove assignments to properties of an object escaping through a property hook
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
opcache.file_update_protection=0
8+
--EXTENSIONS--
9+
opcache
10+
--FILE--
11+
<?php
12+
13+
class D {
14+
public $x = 0;
15+
public $h {
16+
get {
17+
global $g;
18+
$g = $this;
19+
return 1;
20+
}
21+
}
22+
}
23+
24+
function g() {
25+
$o = new D;
26+
$o->h;
27+
$o->x = 42;
28+
}
29+
30+
g();
31+
var_dump($g->x);
32+
33+
class E {
34+
public $x = 0;
35+
public $h {
36+
set {
37+
global $g;
38+
$g = $this;
39+
}
40+
}
41+
}
42+
43+
function h() {
44+
$o = new E;
45+
$o->h = 1;
46+
$o->x = 42;
47+
}
48+
49+
h();
50+
var_dump($g->x);
51+
52+
?>
53+
--EXPECT--
54+
int(42)
55+
int(42)

0 commit comments

Comments
 (0)