xref: /PHP-8.0/ext/ffi/tests/039.phpt (revision f8d79582)
1--TEST--
2FFI 039: Pointer arithmetic
3--SKIPIF--
4<?php require_once('skipif.inc'); ?>
5--INI--
6ffi.enable=1
7--FILE--
8<?php
9$a = FFI::new("int[10]");
10for ($i = 0; $i < 10; $i++) {
11    $a[$i] = $i;
12}
13$p = $a + 0;
14var_dump($p[0]);
15$p += 7;
16var_dump($p[0]);
17$q = $p - 3;
18var_dump($q[0]);
19$q = 1 + $q;
20$p++;
21var_dump($p, $q);
22var_dump($p - $q);
23var_dump($q - $p);
24var_dump($q - $a);
25?>
26--EXPECTF--
27int(0)
28int(7)
29int(4)
30object(FFI\CData:int32_t*)#%d (1) {
31  [0]=>
32  int(8)
33}
34object(FFI\CData:int32_t*)#%d (1) {
35  [0]=>
36  int(5)
37}
38int(3)
39int(-3)
40int(5)
41