Open
Description
I'd like to register a temporary error handler that decorates my global error handler. I usually do that this way:
$previous = null;
$previous = set_error_handler(static function () use (&$previous): bool {
// Special error handling here.
// Fall back to the global error handler
return is_callable($previous) && $previous(...func_get_args());
});
try {
// Do something
} finally {
restore_error_handler();
}
If you know a more elegant way to do this, please enlighten me. Psalm however does not like at all what I'm doing here. 🙈
Minimal version:
<?php
$previous = null;
$previous = set_error_handler(static function () use (&$previous): bool {
return is_callable($previous) && $previous(...func_get_args());
});
https://psalm.dev/r/8d2ca309f8
ERROR: TypeDoesNotContainType - 5:12 - Type null for $previous is never callable
ERROR: InvalidFunctionCall - 5:38 - Cannot treat type never as callable
INFO: UnusedVariable - 4:1 - $previous is never referenced or the value is not used
All three errors are false positives imo.
Metadata
Assignees
Labels
No labels
Activity