diff --git a/Zend/tests/gh16293_001.phpt b/Zend/tests/gh16293_001.phpt new file mode 100644 index 0000000000000..a43c9adc45e65 --- /dev/null +++ b/Zend/tests/gh16293_001.phpt @@ -0,0 +1,19 @@ +--TEST-- +GH-16293: Exception in assert() callback with bail enabled +--FILE-- + +--EXPECTF-- +Warning: assert(): assert(false) failed in %s on line %d + +Warning: Uncaught Error: Invalid callback f1, function "f1" not found or invalid function name in %s:%d +Stack trace: +#0 %s(%d): assert(false, 'assert(false)') +#1 {main} + thrown in %s on line %d diff --git a/Zend/tests/gh16293_002.phpt b/Zend/tests/gh16293_002.phpt new file mode 100644 index 0000000000000..a0cd78eedbb51 --- /dev/null +++ b/Zend/tests/gh16293_002.phpt @@ -0,0 +1,19 @@ +--TEST-- +GH-16293: Exception in assert() callback with bail enabled +--FILE-- + +--EXPECTF-- +Warning: assert(): assert(false) failed in %s on line %d + +Warning: Uncaught Exception: Boo in %s:%d +Stack trace: +%a diff --git a/ext/standard/assert.c b/ext/standard/assert.c index 1c5108b94e5b2..f318b1c834067 100644 --- a/ext/standard/assert.c +++ b/ext/standard/assert.c @@ -195,6 +195,11 @@ PHP_FUNCTION(assert) } if (ASSERTG(bail)) { + if (EG(exception)) { + /* The callback might have thrown. Use E_WARNING to print the + * exception so we can avoid bailout and use unwind_exit. */ + zend_exception_error(EG(exception), E_WARNING); + } zend_throw_unwind_exit(); RETURN_THROWS(); } else {