summaryrefslogtreecommitdiff
path: root/ext/ffi/tests/bug79177.phpt
blob: 994ccfa6b9c74076df8d52fe2b2e26f3acf18689 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
--TEST--
Bug #79177 (FFI doesn't handle well PHP exceptions within callback)
--SKIPIF--
<?php
if (!extension_loaded('ffi')) die('skip ffi extension not available');
if (!extension_loaded('zend_test')) die('skip zend_test extension not available');
?>
--FILE--
<?php
require_once __DIR__ . '/utils.inc';
$header = <<<HEADER
extern int *(*bug79177_cb)(void);
void bug79177(void);
HEADER;

if (PHP_OS_FAMILY !== 'Windows') {
    $ffi = FFI::cdef($header);
} else {
    try {
        $ffi = FFI::cdef($header, 'php_zend_test.dll');
    } catch (FFI\Exception $ex) {
        $ffi = FFI::cdef($header, ffi_get_php_dll_name());
    }
}

$ffi->bug79177_cb = function() {
    throw new \RuntimeException('Not allowed');
};
try { 
    $ffi->bug79177(); // this is supposed to raise a fatal error
} catch (\Throwable $exception) {}
echo "done\n";
?>
--EXPECTF--
Warning: Uncaught RuntimeException: Not allowed in %s:%d
Stack trace:
#0 %s(%d): {closure}()
#1 %s(%d): FFI->bug79177()
#2 {main}
  thrown in %s on line %d

Fatal error: Throwing from FFI callbacks is not allowed in %s on line %d