psalm: InvalidArugment for `set_error_handler` when using `[$this, 'method']` construct
One way to specify an error handler is to pass in an array with two elements, an object or classname and a methodname:
// ...
private function registerLocalErrorHandler(): void {
$this->originalHandler = \set_error_handler(
[$this, 'localErrorHandler']
);
}
public function localErrorHandler(int $errno, string $errstr): void {
throw new PharInstallerException($errstr, $errno);
}
// ...
When running psalm, it complains:
ERROR: InvalidArgument - src/services/phar/PharInstaller.php:102:13 - Argument 1 of set_error_handler expects callable(int, string, string=, int=, array<array-key, mixed>=):bool|null, array{PharIo\Phive\PharInstaller&static, string(localErrorHandler)} provided (see https://psalm.dev/004)
[$this, 'localErrorHandler']
The error is either wrong because this construct is perfectly valid or, in case psalm looks at the actual signature of the referenced method, confusingly wrong as the signature doesn’t match but is technically compatible.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 16
Commits related to this issue
- Fixes Psalm's "InvalidArgument" error. I just removed the return type from the "exceptionErrorHandler". There is in fact a hacky solution, that I didn't like: https://github.com/vimeo/psalm/issues/35... — committed to fsamapoor/server by fsamapoor a year ago
- Fixes Psalm's "InvalidArgument" error. I just removed the return type from the "exceptionErrorHandler". There is in fact a hacky solution, that I didn't like: https://github.com/vimeo/psalm/issues/35... — committed to fsamapoor/server by fsamapoor a year ago
- Fixes Psalm's "InvalidArgument" error. I just removed the return type from the "exceptionErrorHandler". There is in fact a hacky solution, that I didn't like: https://github.com/vimeo/psalm/issues/35... — committed to fsamapoor/server by fsamapoor a year ago
The error will go away if you set the error handler to return
?bool
, but this error should also probably not happen in the first place.