Skip to content

Add Method to UnhandledMatchError to get the Unhandled Value #14490

@donatj

Description

@donatj

Description

When catching a failed match it would be very handy if the UnhandledMatchError had a method such as getUnmatchedValue() : mixed that contained the actual unmatched value.

This could allow more graceful handling of failed match handlers.

This would allow as a very basic example:

function getTypeName( mixed $value ) : string {
    return match (gettype($value)) {
        'integer', 'double' => 'number',
        'string'            => 'string',
        'NULL'              => 'null',
    };
}

try {
    getTypeName($item);
} catch(\UnhandledMatchError $e) {
    $log->info("Received unhandled type: " . $e->getUnmatchedValue());
}

I'm sure there is more involved handling you could do with it as well.

@derickr advised me to open a ticket for this idea

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions