Fix UnhandledMatchError in PHP
What the message means
UnhandledMatchError occurs when a match expression has no arm for the supplied value. Match compares types as well as values. The integer 1 and the string "1" are different cases.
Record a non-sensitive example of the value and its type at the failing expression rather than logging the entire request.
Before you change anything
Save the complete error line and its timestamp in a private note. Record the failed action, the active PHP version and any components updated at the same time. Do not post passwords, customer details or full server paths in a public support forum.
Back up both files and the database before making changes. Check that the backup can actually be restored. Use a protected test copy with the same PHP version and relevant settings, with real payments and outgoing customer emails disabled.
A difference hidden on screen
This example uses text received from a form: $status = '1'; $name = match ($status) { 1 => 'ready' };. The arm for integer 1 does not handle that string. Including the type in the diagnosis reveals the mismatch even though both values may be displayed as 1.
If the integration specifies text codes, an arm using '1' matches that agreement. If it specifies integers, investigate why text was supplied. Converting the value before making that decision can conceal a different problem.
The useful question for the administrator is which status arrived and which status the application should have saved for it.
Trace the failing operation
Ask the developer which values the supplying integration is allowed to send. Compare that agreement with the cases in the code. For example, investigate a delivery status missing from a translation table.
Establish whether the integration sent unexpected input or the application omitted a valid case that it should already support.
Do not add a default arm that treats every unknown status as success. Write down what the visitor or administrator should see for an unrecognized value. For a payment status, an unknown result should not automatically release an order.
Have the responsible owner decide whether rejection, waiting or a specific error message is appropriate.
Five steps to repair
- Locate the match expression from the error line. Record a non-sensitive example value and the exact type that reaches it.
- Compare the input with every existing arm. Check the integration contract before converting values to a different type.
- Add the intended missing handling or repair invalid input. Define the behavior for unknown values as a separate decision.
- Test every permitted case and at least one unknown case. Include numbers and identically written strings as distinct inputs.
- Repeat the original action and inspect saved status and displayed message. Confirm that unknown input cannot become an unintended success.
A concrete acceptance test
Use an invented shipping integration with registered and delivered statuses. Then deliberately supply an unknown status. Accept the repair when recognized cases display correctly and the unknown case produces the agreed message.
Also inspect the saved test order: it must not accidentally become delivered. Record the expected outcome for each input so future statuses are added deliberately rather than silently accepted by a catch-all branch.
Updating WordPress or WooCommerce components
If the error points to a plugin or theme, first check whether its author documents a relevant update. Record the installed version before trying that update on the test copy. Include any custom extensions that depend on the component in your checks.
Avoid editing supplier files without an agreed maintenance plan. A later update can overwrite a manual repair. For custom code, ask for a change that is kept with the source code and can be tested again during the next PHP update.
When to ask for help
Use the existing PHP update service if you cannot trace the error or if it affects orders, payments or saved records. Describe the failed action and the expected result in the help form below. An error message alone does not identify which component needs to change.
Check your PHP version
Use the Exposure Check link below this article to check your PHP version where it is publicly visible. If that information is unavailable, ask your host to confirm the active version. This check cannot read private logs and does not prove that the programming error is fixed.
Visit the PHP security status page for the separate assessment of your PHP version. Save the versions, code change and test outcome in your maintenance notes. Let the responsible maintainer decide when the tested repair should be applied to the live website.