bug79177.phpt 936 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. --TEST--
  2. Bug #79177 (FFI doesn't handle well PHP exceptions within callback)
  3. --EXTENSIONS--
  4. ffi
  5. zend_test
  6. --FILE--
  7. <?php
  8. require_once __DIR__ . '/utils.inc';
  9. $header = <<<HEADER
  10. extern int *(*bug79177_cb)(void);
  11. void bug79177(void);
  12. HEADER;
  13. if (PHP_OS_FAMILY !== 'Windows') {
  14. $ffi = FFI::cdef($header);
  15. } else {
  16. try {
  17. $ffi = FFI::cdef($header, 'php_zend_test.dll');
  18. } catch (FFI\Exception $ex) {
  19. $ffi = FFI::cdef($header, ffi_get_php_dll_name());
  20. }
  21. }
  22. $ffi->bug79177_cb = function() {
  23. throw new \RuntimeException('Not allowed');
  24. };
  25. try {
  26. $ffi->bug79177(); // this is supposed to raise a fatal error
  27. } catch (\Throwable $exception) {}
  28. echo "done\n";
  29. ?>
  30. --EXPECTF--
  31. Warning: Uncaught RuntimeException: Not allowed in %s:%d
  32. Stack trace:
  33. #0 %s(%d): {closure}()
  34. #1 %s(%d): FFI->bug79177()
  35. #2 {main}
  36. thrown in %s on line %d
  37. Fatal error: Throwing from FFI callbacks is not allowed in %s on line %d