xref: /php-src/ext/ffi/tests/101.phpt (revision db991bc0)
1--TEST--
2FFI 101: PHP symbols (function address)
3--EXTENSIONS--
4ffi
5--SKIPIF--
6<?php
7try {
8    FFI::cdef("extern void *zend_printf;");
9} catch (Throwable $e) {
10    die('skip PHP symbols not available');
11}
12?>
13--INI--
14ffi.enable=1
15--FILE--
16<?php
17require_once('utils.inc');
18$fastcall = ffi_get_fastcall_specifier();
19$zend = FFI::cdef("
20    const char *get_zend_version(void);
21    //char *get_zend_version(void);
22    extern size_t (*zend_printf)(const char *format, ...);
23
24    unsigned long $fastcall zend_hash_func(const char *str, size_t len);
25
26    void $fastcall zend_str_tolower(char *str, size_t length);
27
28");
29$f = $zend->get_zend_version;
30var_dump(trim(explode("\n",$f())[0]));
31//var_dump(trim(FFI::string($zend->get_zend_version())));
32var_dump($zend->zend_printf);
33var_dump(($zend->zend_printf)("Hello %s!\n", "World"));
34
35$f = $zend->zend_hash_func;
36var_dump($f("file", strlen("file")));
37
38$str = $zend->new("char[16]");
39FFI::memcpy($str, "Hello World!", strlen("Hello World!"));
40$f = $zend->zend_str_tolower;
41$f($str, strlen("Hello World!"));
42var_dump(FFI::string($str));
43
44?>
45--EXPECTF--
46string(%d) "Zend Engine %s"
47object(FFI\CData:uint%d_t(*)())#%d (1) {
48  [0]=>
49  object(FFI\CData:uint%d_t())#%d (0) {
50  }
51}
52Hello World!
53int(13)
54int(%i)
55string(12) "hello world!"
56