Skip to content

Commit 1235334

Browse files
committed
Verify closures can access $this
1 parent ed8144e commit 1235334

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/test/php/lang/ast/unittest/emit/InitializeWithExpressionsTest.class.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@ public function run() {
5050
Assert::equals(new Handle(1), $r(new Handle(0)));
5151
}
5252

53+
#[Test]
54+
public function using_closures_referencing_this() {
55+
$r= $this->run('use lang\ast\unittest\emit\Handle; class <T> {
56+
private $id= 1;
57+
private $h= fn() => new Handle($this->id);
58+
59+
public function run() {
60+
return $this->h;
61+
}
62+
}');
63+
Assert::equals(new Handle(1), $r());
64+
}
65+
5366
#[Test]
5467
public function using_anonymous_classes() {
5568
$r= $this->run('class <T> {

0 commit comments

Comments
 (0)