Skip to content

Commit 2cbd440

Browse files
Crellsgolemon
authored andcommitted
Add a test for invokable objects.
1 parent 5f59919 commit 2cbd440

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Invokable objects may be composed
3+
--FILE--
4+
<?php
5+
6+
class Times {
7+
public function __construct(private int $x) {}
8+
9+
public function __invoke(int $y): int
10+
{
11+
return $this->x * $y;
12+
}
13+
}
14+
15+
function double(int $x): int {
16+
return $x * 2;
17+
}
18+
19+
$cb1 = double(...) + new Times(3);
20+
var_dump($cb1(4));
21+
22+
$cb2 = new Times(3) + double(...);
23+
var_dump($cb2(4));
24+
25+
--EXPECT--
26+
int(24)
27+
int(24)

0 commit comments

Comments
 (0)