Skip to content

Commit cc381b5

Browse files
committed
Fix #407: Cannot bind closure.
1 parent 633f7c5 commit cc381b5

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

jphp-core/tests/org/develnext/jphp/core/compiler/jvm/ClosuresTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,9 @@ public void testBug266() {
5555
public void testBug370() {
5656
check("closures/bug370.phpt");
5757
}
58+
59+
@Test
60+
public void testBug407() {
61+
check("closures/bug407.phpt");
62+
}
5863
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Cannot bind closure
3+
--FILE--
4+
<?php
5+
function &getVar($obj, string $var)
6+
{
7+
return \Closure::bind(
8+
function & () use ($var) {
9+
return $this->{$var};
10+
},
11+
$obj,
12+
\get_class($obj)
13+
)();
14+
}
15+
class a { private $help = 'abc'; }
16+
17+
var_dump(getVar(new a, 'help'));
18+
?>
19+
--EXPECTF--
20+
string(3) "abc"

jphp-runtime/src/php/runtime/lang/Closure.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ public static Memory bind(Environment env, Memory... args) throws CloneNotSuppor
160160
Closure closure = args[0].toObject(Closure.class);
161161

162162
Closure newClosure = (Closure) closure.clone();
163-
newClosure.self = args[0];
164-
newClosure.scope = args[1].toString();
163+
newClosure.self = args[1];
164+
newClosure.scope = args[2].toString();
165165
return new ObjectMemory(newClosure);
166166
}
167167

0 commit comments

Comments
 (0)