Bug #81303 [NEW]: Error message for match() is misleading and unhelpful
| From: | crell@php.net | Date: | Tue, 27 Jul 2021 16:45:59 +0000 |
| Subject: | Bug #81303 [NEW]: Error message for match() is misleading and unhelpful | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-235414@lists.php.net to get a copy of this message | ||
From: crell
Operating system: Linux
PHP version: 8.0.8
Package: Scripting Engine problem
Bug Type: Bug
Bug description:Error message for match() is misleading and unhelpful
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 bug report at https://bugs.php.net/bug.php?id=81303&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=81303&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=81303&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=81303&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=81303&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=81303&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=81303&r=support
Expected behavior: https://bugs.php.net/fix.php?id=81303&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=81303&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=81303&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=81303&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=81303&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=81303&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=81303&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=81303&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=81303&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=81303&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=81303&r=mysqlcfg