Reputation: 56555
I have been using:
assert_options (ASSERT_CALLBACK, function(string $file, int $line, ?string $assertion, string $description = null){
// my codes
}
However, assert_options
has been deprecated as of PHP 8.3. What are other compatible alternatives to hook a function as default assert
callback?
Upvotes: 2
Views: 321
Reputation: 56555
Bard has surfaced a good alternative:
namespace my_ns;
function my_assert_handler(Throwable $e) {
if ($e instanceof AssertionError) {
// Your callback logic here
echo "Assertion failed: " . $e->getMessage() . PHP_EOL;
}
}
set_exception_handler('my_ns\my_assert_handler');
Upvotes: 0