Bug #81303 [Opn->Csd]: Error message for match() is misleading and unhelpful

From: Date: Mon, 02 Aug 2021 15:32:20 +0000
Subject: Bug #81303 [Opn->Csd]: Error message for match() is misleading and unhelpful
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-235531@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 Updated by: git@php.net Reported by: crell@php.net Summary: Error message for match() is misleading and unhelpful -Status: Open +Status: Closed Type: Bug Package: Scripting Engine problem Operating System: Linux PHP Version: 8.0.8 Block user comment: N Private report: N New Comment: Automatic comment on behalf of krakjoe Revision: https://github.com/php/php-src/commit/05ef6334cdf9bec98e056c0a80bd02a0a0ab242f Log: Fix bug #81303 improve match errors Previous Comments: ------------------------------------------------------------------------ [2021-07-27 20:34:44] crell@php.net 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 ------------------------------------------------------------------------ [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

« previous php.bugs (#235531) next »