<?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);
- Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
- log exception
object(TypeError)#2 (7) {
["message":protected]=>
string(107) "accept_callable(): Argument #1 ($arg) must be of type callable, array given, called in /in/rjRSm on line 27"
["string":"Error":private]=>
string(0) ""
["code":protected]=>
int(0)
["file":protected]=>
string(9) "/in/rjRSm"
["line":protected]=>
int(3)
["trace":"Error":private]=>
array(1) {
[0]=>
array(4) {
["file"]=>
string(9) "/in/rjRSm"
["line"]=>
int(27)
["function"]=>
string(15) "accept_callable"
["args"]=>
array(1) {
[0]=>
array(2) {
[0]=>
string(3) "Foo"
[1]=>
string(9) "log_error"
}
}
}
}
["previous":"Error":private]=>
NULL
}
preferences:
65.45 ms | 408 KiB | 5 Q