|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81303 Error message for match() is misleading and unhelpful
Submitted: 2021-07-27 16:45 UTC Modified: -
From: Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 8.0.8 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
New email:
PHP Version: OS:


 [2021-07-27 16:45 UTC]
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',
} catch (UnhandledMatchError $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) {
  string(36) "Unhandled match value of type string"
  string(0) ""
  string(9) "/in/U4Ns2"
  array(0) {


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-07-27 20:34 UTC]
The following pull request has been associated:

Patch Name: Improve match() error messages
On GitHub:
 [2021-08-02 15:32 UTC]
Automatic comment on behalf of krakjoe
Log: Fix bug #81303 improve match errors
 [2021-08-02 15:32 UTC]
-Status: Open +Status: Closed
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 20 01:01:32 2024 UTC