PHP 8.2 proposal: "match", allow "default" as conditional_expression, e.g. 'en_US', 'en_GB', default => loadDefaults()
| From: | Andreas | Date: | Mon, 22 Nov 2021 18:18:29 +0000 |
| Subject: | PHP 8.2 proposal: "match", allow "default" as conditional_expression, e.g. 'en_US', 'en_GB', default => loadDefaults() | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-116479@lists.php.net to get a copy of this message | ||
Hi internals,
This is a proposal to allow to append the
default pattern by comma to
the end of the last match branch. (Like a conditional_expression)
This allows to re-use the return_expression if required and avoids code
duplication.
PROPOSAL: PHP 8.2
<?php
return match ($locale) {
'de_DE', 'de_CH', 'de_AT' => loadGermanLanguageSettings(), 'en_US', 'en_GB', default => loadDefaultLanguageSettings(),}; ?> // PHP 8.1 (Current implementation works like before) <?php return match ($locale) {
'de_DE', 'de_CH', 'de_AT' => loadGermanLanguageSettings(), 'en_US', 'en_GB' => loadDefaultLanguageSettings(), default => loadDefaultLanguageSettings(),}; ?> The
default pattern must be the last item in the last expression branch.
Thanks,
Andreas