Skip to content

Commit 648bb68

Browse files
committed
Add FFI example to tests
1 parent 8a18672 commit 648bb68

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
Test array_sum() function with objects that implement addition but not castable to numeric type
3+
--EXTENSIONS--
4+
ffi
5+
--FILE--
6+
<?php
7+
8+
$x = FFI::new("int[2]");
9+
$x[0] = 10;
10+
$x[1] = 25;
11+
12+
$input = [$x, 1];
13+
14+
echo "array_sum() version:\n";
15+
var_dump(array_sum($input));
16+
17+
echo "array_reduce() version:\n";
18+
var_dump(array_reduce($input, fn($carry, $value) => $carry + $value, 0));
19+
?>
20+
--EXPECTF--
21+
array_sum() version:
22+
23+
Warning: Object of class FFI\CData could not be converted to int|float in %s on line %d
24+
int(0)
25+
array_reduce() version:
26+
object(FFI\CData:int32_t*)#4 (1) {
27+
[0]=>
28+
int(25)
29+
}

0 commit comments

Comments
 (0)