xref: /PHP-8.0/ext/ffi/tests/100.phpt (revision c5401854)
1--TEST--
2FFI 100: PHP symbols
3--SKIPIF--
4<?php require_once('skipif.inc'); ?>
5<?php require_once('utils.inc'); ?>
6<?php
7try {
8    ffi_cdef("extern void *zend_printf;", ffi_get_php_dll_name());
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", ffi_get_php_dll_name());
29var_dump(trim(explode("\n",$zend->get_zend_version())[0]));
30//var_dump(trim(FFI::string($zend->get_zend_version())));
31var_dump($zend->zend_printf);
32var_dump(($zend->zend_printf)("Hello %s!\n", "World"));
33
34var_dump($zend->zend_hash_func("file", strlen("file")));
35
36$str = $zend->new("char[16]");
37FFI::memcpy($str, "Hello World!", strlen("Hello World!"));
38$zend->zend_str_tolower($str, strlen("Hello World!"));
39var_dump(FFI::string($str));
40
41?>
42--EXPECTF--
43string(%d) "Zend Engine %s"
44object(FFI\CData:uint%d_t(*)())#%d (1) {
45  [0]=>
46  object(FFI\CData:uint%d_t())#%d (0) {
47  }
48}
49Hello World!
50int(13)
51int(%i)
52string(12) "hello world!"
53