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