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