[php-src] Issue #14490: Add Method to UnhandledMatchError to get the Unhandled Value
| From: | donatj | Date: | Thu, 06 Jun 2024 18:22:09 +0000 |
| Subject: | [php-src] Issue #14490: Add Method to UnhandledMatchError to get the Unhandled Value | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-247051@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/14490
Author: 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:
```php
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 PR for this issue