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