Problem/Motivation
PHP 8.5 introduces get_error_handler
. Before this, the only way to get the handler was to set it to something else, then restore it.
Steps to reproduce
See \Drupal\Core\Utility\Error::currentErrorHandler
:
public static function currentErrorHandler(): ?callable {
$currentHandler = set_error_handler('var_dump');
restore_error_handler();
return $currentHandler;
}
There are a few other places that use set_error_handler
to get the current handler, but they are also intentionally setting the error handler at the same time. It would probably be clearer to use get_error_handler
first.
$ grep -r " = set_error_handler" core
core/lib/Drupal/Core/Utility/Error.php: $currentHandler = set_error_handler('var_dump');
core/lib/Drupal/Core/Render/ElementInfoManager.php: $previous_error_handler = set_error_handler(function ($severity, $message, $file, $line) use (&$previous_error_handler) {
core/tests/Drupal/KernelTests/Core/Render/Element/DeprecatedElementTest.php: $previous_error_handler = set_error_handler(function ($severity, $message, $file, $line) use (&$previous_error_handler) {
core/tests/Drupal/KernelTests/Core/Render/Element/DeprecatedElementTest.php: $previous_error_handler = set_error_handler(function ($severity, $message, $file, $line) use (&$previous_error_handler) {
core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryTest.php: $previous_error_handler = set_error_handler(function ($severity, $message, $file, $line) use (&$previous_error_handler) {
Proposed resolution
Add symfony/polyfill-php85
Update above instances to use get_error_handler
Remaining tasks
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet