Bug #81303 [PATCH]: Error message for match() is misleading and unhelpful
| From: | crell@php.net | Date: | Tue, 27 Jul 2021 20:34:44 +0000 |
| Subject: | Bug #81303 [PATCH]: Error message for match() is misleading and unhelpful | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-235415@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=81303&edit=1
ID: 81303
Patch added by: crell@php.net
Reported by: crell@php.net
Summary: Error message for match() is misleading and
unhelpful
Status: Open
Type: Bug
Package: Scripting Engine problem
Operating System: Linux
PHP Version: 8.0.8
Block user comment: N
Private report: N
New Comment:
The following pull request has been associated:
Patch Name: Improve match() error messages
On GitHub: https://github.com/php/php-src/pull/7312
Patch: https://github.com/php/php-src/pull/7312.patch
Previous Comments:
------------------------------------------------------------------------
[2021-07-27 16:45:59] crell@php.net
Description:
------------
When a match() statement finds no matching arm, it throws an exception. The exception's error
message text, however, is very generic. Specifically, it reads "Unhandled match value of type
$type_of_the_match_var". The type of the variable is rarely useful in that case. The *value*
of the variable is what didn't match, so that's what should be in the message. However,
it's not even in the thrown object at all.
Test script:
---------------
try {
$v = match('float') {
'string' => 's',
'int' => 'i',
};
var_dump($v);
} catch (UnhandledMatchError $e) {
var_dump($e);
}
Expected result:
----------------
An exception thrown with a less misleading error message string, including the value of the
variable, not its type.
Actual result:
--------------
object(UnhandledMatchError)#1 (7) {
["message":protected]=>
string(36) "Unhandled match value of type string"
["string":"Error":private]=>
string(0) ""
["code":protected]=>
int(0)
["file":protected]=>
string(9) "/in/U4Ns2"
["line":protected]=>
int(4)
["trace":"Error":private]=>
array(0) {
}
["previous":"Error":private]=>
NULL
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=81303&edit=1