[php-src] Issue #8039: Better error messages for type callable

From: Date: Fri, 04 Feb 2022 22:58:56 +0000
Subject: [php-src] Issue #8039: Better error messages for type callable
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-239491@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/8039 Author: dg ### Description I deliberately avoid the callable type in my code because it produces misleading error messages. Examples: ```php $cb = [PhpTokn::class, 'tokenize']; // typo in class name (fn(callable $cb) => 0)($cb); // expected error: Argument #1 ($cb) must be of type callable, class "PhpTokn" does not exist // current error: Argument #1 ($cb) must be of type callable, array given ``` ```php $cb = [PhpToken::class, 'tokenze']; // typo in method name (fn(callable $cb) => 0)($cb); // expected error: Argument #1 ($cb) must be of type callable, method PhpToken::tokenze() does not exist // current error: Argument #1 ($cb) must be of type callable, array given ``` ```php $cb = 'PhpTokn::tokenize'; // typo in class name (fn(callable $cb) => 0)($cb); // expected error: Argument #1 ($cb) must be of type callable, class "PhpTokn" does not exist // current error: Argument #1 ($cb) must be of type callable, string given ``` ```php $cb = 'PhpToken::tokenze'; // typo in method name (fn(callable $cb) => 0)($cb); // expected error: Argument #1 ($cb) must be of type callable, method PhpToken::tokenze() does not exist // current error: Argument #1 ($cb) must be of type callable, string given ``` Not only does the error message not tell you exactly what is wrong with the callback, but it is also misleading. Message *Must be callable, array given* suggests, that something other than array (or string) was expected. Thanks for your consideration.

« previous php.bugs (#239491) next »