100.phpt 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. --TEST--
  2. FFI 100: PHP symbols
  3. --EXTENSIONS--
  4. ffi
  5. --SKIPIF--
  6. <?php require_once('utils.inc'); ?>
  7. <?php
  8. try {
  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--
  15. ffi.enable=1
  16. --FILE--
  17. <?php
  18. require_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. unsigned long $fastcall zend_hash_func(const char *str, size_t len);
  25. void $fastcall zend_str_tolower(char *str, size_t length);
  26. ", ffi_get_php_dll_name());
  27. var_dump(trim(explode("\n",$zend->get_zend_version())[0]));
  28. //var_dump(trim(FFI::string($zend->get_zend_version())));
  29. var_dump($zend->zend_printf);
  30. var_dump(($zend->zend_printf)("Hello %s!\n", "World"));
  31. var_dump($zend->zend_hash_func("file", strlen("file")));
  32. $str = $zend->new("char[16]");
  33. FFI::memcpy($str, "Hello World!", strlen("Hello World!"));
  34. $zend->zend_str_tolower($str, strlen("Hello World!"));
  35. var_dump(FFI::string($str));
  36. ?>
  37. --EXPECTF--
  38. string(%d) "Zend Engine %s"
  39. object(FFI\CData:uint%d_t(*)())#%d (1) {
  40. [0]=>
  41. object(FFI\CData:uint%d_t())#%d (0) {
  42. }
  43. }
  44. Hello World!
  45. int(13)
  46. int(%i)
  47. string(12) "hello world!"