Re: PHP 8.2 proposal: "match", allow "default" as conditional_expression, e.g. 'en_US', 'en_GB', default => loadDefaults()
| From: | Nikita Popov | Date: | Mon, 22 Nov 2021 21:06:47 +0000 |
| Subject: | Re: PHP 8.2 proposal: "match", allow "default" as conditional_expression, e.g. 'en_US', 'en_GB', default => loadDefaults() | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-116480@lists.php.net to get a copy of this message | ||
On Mon, Nov 22, 2021 at 7:18 PM Andreas <syntheme@gmx.de> wrote:
> 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(),
> };
> ?>
>
Isn't this equivalent to just this?
<?php
return match ($locale) {
'de_DE', 'de_CH', 'de_AT' => loadGermanLanguageSettings(),
default => loadDefaultLanguageSettings(),
};
'en_US' and 'en_GB' will already go to the default branch if they're not
listed explicitly.
Regards,
Nikita