Re: Putting the match expression in constant expressions in PHP 8.0 or 8.1
| From: | Guilliam Xavier | Date: | Sat, 08 Aug 2020 16:09:33 +0000 |
| Subject: | Re: Putting the match expression in constant expressions in PHP 8.0 or 8.1 | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-111378@lists.php.net to get a copy of this message | ||
On Sat, Aug 8, 2020 at 2:22 AM tyson andre <tysonandre775@hotmail.com>
wrote:
> Hi internals,
>
> The match expression can be thought of as a much more concise/readable
> equivalent to chained ternary operators.
> I'm proposing allowing matches in constant expressions when all parts of
> the match are constant expressions.
>
> For example, these two class constants would have equivalent behaviors if
> match expressions were allowed in constant expressions.
>
> ```
> class MyClass {
> const CONFIG_SETTING = (APP_ENVIRONMENT == 'dev' || APP_ENVIRONMENT ==
> 'stage') ? 'development-config' :
> (APP_ENVIRONMENT == 'prod' ? 'production-config' : null);
>
> const CONFIG_SETTING = match(APP_ENVIRONMENT) {
> 'dev', 'stage' => 'development-config',
> 'prod' => 'production-config',
> default => null,
> };
> }
> ```
>
> https://github.com/php/php-src/pull/5951 implements the main
> part of the
> change.
>
Hi, thanks, just noticed that your examples should use
=== not ==.
Regards
--
Guilliam Xavier