blob: f665c67ff691fc795b84c756e765af6261a170e7 (
plain)
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
56
57
58
59
60
61
62
63
64
65
66
67
|
--TEST--
Closure::call
--FILE--
<?php
class Foo {
public $x = 0;
function bar() {
return function () {
return $this->x;
};
}
}
$foo = new Foo;
$qux = $foo->bar();
$foobar = new Foo;
$foobar->x = 3;
var_dump($qux());
var_dump($qux->call($foo));
// Try on an object other than the one already bound
var_dump($qux->call($foobar));
$bar = function () {
return $this->x;
};
$elePHPant = new StdClass;
$elePHPant->x = 7;
// Try on a StdClass
var_dump($bar->call($elePHPant));
$beta = function ($z) {
return $this->x * $z;
};
// Ensure argument passing works
var_dump($beta->call($foobar, 7));
// Ensure ->call calls with scope of passed object
class FooBar {
private $x = 3;
}
$foo = function () {
var_dump($this->x);
};
$foo->call(new FooBar);
?>
--EXPECTF--
int(0)
int(0)
int(3)
Warning: Cannot bind closure to scope of internal class stdClass in %s line %d
NULL
int(21)
int(3)
|