Skip to content

Commit 9840695

Browse files
committed
Fix PHP 7.x compatiblity for Method::closure()
1 parent f21ea0d commit 9840695

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/main/php/lang/reflection/Method.class.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,20 @@ class Method extends Routine {
1919
*/
2020
public function closure($instance= null) {
2121
try {
22-
return $this->reflect->getClosure($instance);
22+
$closure= $this->reflect->getClosure($instance);
2323
} catch (\Throwable $e) {
2424
throw new IllegalArgumentException($e->getMessage());
2525
}
26+
27+
// PHP 7.x generates warnings and returns NULL instead of throwing an
28+
// exception from ReflectionMethod::getClosure()
29+
if (null === $closure) {
30+
$e= new IllegalArgumentException('Cannot get closure');
31+
\xp::gc(__FILE__);
32+
throw $e;
33+
}
34+
35+
return $closure;
2636
}
2737

2838
/**

0 commit comments

Comments
 (0)