-
Notifications
You must be signed in to change notification settings - Fork 147
/
closure_set_inside_object_methods.phpt
55 lines (47 loc) · 1.14 KB
/
closure_set_inside_object_methods.phpt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
--TEST--
Check if closure can safely use variable names also present in outside scope
--ENV--
DD_TRACE_WARN_LEGACY_DD_TRACE=0
--FILE--
<?php
class Test {
public function m($v){
echo "METHOD " . $v . PHP_EOL;
}
}
$variable = 1000;
final class TestSetup {
public function setup(){
dd_trace("Test", "m", function($i) {
$variable = $i + 10;
$this->m($variable);
echo "HOOK " . $variable . PHP_EOL;
});
}
public function setup_ext($j){
dd_trace("Test", "m", function($i) use ($j){
global $variable;
$variable += $i + $j;
$this->m($variable);
echo "HOOK " . $variable . PHP_EOL;
});
}
}
// Cannot call a function while it is not traced and later expect it to trace
//(new Test())->m(0);
// use convoluted way to execute to test if it also works
$o = new TestSetup();
$reflectionMethod = new ReflectionMethod('TestSetup', 'setup');
$reflectionMethod->invoke($o);
(new Test())->m(1);
$o->setup_ext(100);
(new Test())->m(1);
(new Test())->m(10);
?>
--EXPECT--
METHOD 11
HOOK 11
METHOD 1101
HOOK 1101
METHOD 1211
HOOK 1211