Skip to content

Commit 608a22e

Browse files
Crellkrakjoe
authored andcommitted
Add test for fromCallable().
1 parent ddd37f0 commit 608a22e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
Converting partials to closures.
3+
--FILE--
4+
<?php
5+
6+
function volume(int $x, int $y, int $z): int {
7+
return $x * $y * $z;
8+
}
9+
10+
$p = volume(3, 5, ?);
11+
12+
// This is a useful and common way to normalize different types of callable
13+
// to a single API for reflection purposes.
14+
$c = Closure::fromCallable($p);
15+
$ref = new ReflectionFunction($c);
16+
17+
print $ref->getNumberOfParameters() . PHP_EOL;
18+
print $ref->getParameters()[0]->getType() . PHP_EOL;
19+
print $ref->getParameters()[0]->getName() . PHP_EOL;
20+
21+
print $ref->getReturnType() . PHP_EOL;
22+
23+
?>
24+
--EXPECTF--
25+
1
26+
int
27+
z
28+
int

0 commit comments

Comments
 (0)