xref: /PHP-8.1/ext/ffi/tests/008.phpt (revision bd9f4fa6)
1--TEST--
2FFI 008: Array iteration
3--EXTENSIONS--
4ffi
5--INI--
6ffi.enable=1
7--FILE--
8<?php
9$a = FFI::new("int[3]");
10$a[1] = 10;
11$a[2] = 20;
12var_dump(count($a));
13foreach ($a as $key => $val) {
14    echo "$key => $val\n";
15}
16
17$a = FFI::new("struct {int x,y;}");
18try {
19    var_dump(count($a));
20} catch (Throwable $e) {
21    echo get_class($e) . ": " . $e->getMessage()."\n";
22}
23
24try {
25    foreach ($a as $key => $val) {
26        echo "$key => $val\n";
27    }
28} catch (Throwable $e) {
29    echo get_class($e) . ": " . $e->getMessage()."\n";
30}
31?>
32--EXPECT--
33int(3)
340 => 0
351 => 10
362 => 20
37FFI\Exception: Attempt to count() on non C array
38FFI\Exception: Attempt to iterate on non C array
39