101.phpt 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. --TEST--
  2. FFI 101: PHP symbols (function address)
  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. $f = $zend->get_zend_version;
  28. var_dump(trim(explode("\n",$f())[0]));
  29. //var_dump(trim(FFI::string($zend->get_zend_version())));
  30. var_dump($zend->zend_printf);
  31. var_dump(($zend->zend_printf)("Hello %s!\n", "World"));
  32. $f = $zend->zend_hash_func;
  33. var_dump($f("file", strlen("file")));
  34. $str = $zend->new("char[16]");
  35. FFI::memcpy($str, "Hello World!", strlen("Hello World!"));
  36. $f = $zend->zend_str_tolower;
  37. $f($str, strlen("Hello World!"));
  38. var_dump(FFI::string($str));
  39. ?>
  40. --EXPECTF--
  41. string(%d) "Zend Engine %s"
  42. object(FFI\CData:uint%d_t(*)())#%d (1) {
  43. [0]=>
  44. object(FFI\CData:uint%d_t())#%d (0) {
  45. }
  46. }
  47. Hello World!
  48. int(13)
  49. int(%i)
  50. string(12) "hello world!"