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