-
Notifications
You must be signed in to change notification settings - Fork 824
Open
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.
Metadata
Metadata
Assignees
Labels
No labels