Merge branch 'PHP-8.4'

* PHP-8.4:
  Fix exception in assert() callback with bail enabled
This commit is contained in:
Ilija Tovilo 2024-10-14 14:01:26 +02:00
commit 41958082bd
No known key found for this signature in database
GPG key ID: 5050C66BFCD1015A
3 changed files with 43 additions and 0 deletions

View file

@ -0,0 +1,19 @@
--TEST--
GH-16293: Exception in assert() callback with bail enabled
--FILE--
<?php
assert_options(ASSERT_EXCEPTION, 0);
assert_options(ASSERT_BAIL, 1);
assert_options(ASSERT_CALLBACK, 'f1');
assert(false);
?>
--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

View file

@ -0,0 +1,19 @@
--TEST--
GH-16293: Exception in assert() callback with bail enabled
--FILE--
<?php
assert_options(ASSERT_EXCEPTION, 0);
assert_options(ASSERT_BAIL, 1);
assert_options(ASSERT_CALLBACK, function () {
throw new Exception('Boo');
});
assert(false);
?>
--EXPECTF--
Warning: assert(): assert(false) failed in %s on line %d
Warning: Uncaught Exception: Boo in %s:%d
Stack trace:
%a

View file

@ -238,6 +238,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 {