File tree Expand file tree Collapse file tree 1 file changed +58
-0
lines changed
tests/language-feature-scripts Expand file tree Collapse file tree 1 file changed +58
-0
lines changed Original file line number Diff line number Diff line change 1+ --TEST--
2+ Verifies that generated value holder proxy object doesn't loose track of references inside its interceptors
3+ --FILE--
4+ <?php
5+
6+ require_once __DIR__ . '/init.php ' ;
7+
8+ class RefClass
9+ {
10+ public function ref1 (int &$ ref ): void
11+ {
12+ ++$ ref ;
13+ }
14+
15+ public function ref2 (int &$ ref ): void
16+ {
17+ --$ ref ;
18+ }
19+ }
20+
21+ $ factory = new \ProxyManager \Factory \AccessInterceptorValueHolderFactory ($ configuration );
22+ $ proxy = $ factory ->createProxy (
23+ new RefClass (),
24+ [
25+ 'ref1 ' => static function (
26+ object $ proxy ,
27+ RefClass $ instance ,
28+ string $ method ,
29+ array $ args ,
30+ bool &$ returnEarly
31+ ) {
32+ $ returnEarly = true ;
33+ $ instance ->ref1 ($ args ['ref ' ]);
34+ },
35+ ],
36+ [
37+ 'ref2 ' => static function (
38+ object $ proxy ,
39+ RefClass $ instance ,
40+ string $ method ,
41+ array $ args ,
42+ ) {
43+ $ instance ->ref2 ($ args ['ref ' ]);
44+ },
45+ ],
46+ );
47+
48+ $ ref = 0 ;
49+
50+ $ proxy ->ref1 ($ ref );
51+ var_dump ($ ref );
52+
53+ $ proxy ->ref2 ($ ref );
54+ var_dump ($ ref );
55+
56+ --EXPECTF --
57+ int (1 )
58+ int (-1 )
You can’t perform that action at this time.
0 commit comments