set_error_handler and set_exception_handler do not necessarily return a callable
Nobody has claimed this yet.
- Dominant language
- XML
- Stars
- 596
- Forks
- 890
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 55
Description
But just an array, depending on the callable used and the way it was called.
e.g. 2 examples where we don't get a callable but an array (and therefore get an error):
<?php
function accept_callable(callable $arg) {}
class Foo {
public function __construct() {
set_error_handler([__CLASS__, 'log_error']);
set_exception_handler([$this, 'log_exception']);
}
public function log_error( $type, $message, $file, $line ) {
echo "log error" . PHP_EOL;
return true;
}
public function log_exception( $e ) {
echo "log exception" . PHP_EOL;
var_dump($e);
}
}
$foo = new Foo();
$previousHandler = set_error_handler(static fn () => false);
restore_error_handler();
accept_callable($previousHandler);
<?php
function accept_callable(callable $arg) {}
class Foo {
public function __construct() {
set_error_handler([$this, 'log_error']);
set_exception_handler([$this, 'log_exception']);
}
private function log_error( $type, $message, $file, $line ) {
echo "log error" . PHP_EOL;
return true;
}
public function log_exception( $e ) {
echo "log exception" . PHP_EOL;
var_dump($e);
}
}
$foo = new Foo();
$previousHandler = set_error_handler(static fn () => false);
restore_error_handler();
accept_callable($previousHandler);
If you look at the php-src you see that the return type isn't MAY_BE_CALLABLE either, so this is not a bug in PHP but an issue in the docs only.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the PHP documentation entries for set_error_handler() and set_exception_handler(), then compare their documented return values with the two examples and the linked reproductions. Done means the documentation accurately explains that the previous handler may be returned as an array rather than a callable in these cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100