Hi internals > With match this becomes much more concise: > > ```php > $this->handler = function ($var): string { > return match { > null === $var => 'null', > true === $var => 'true', > false === $var => 'false', > \is_string($var) => '"'.$var.'"', > default => rtrim(print_r($var, true)), > }; > }; > ```
I suspect most use cases of `match (true)` are exactly for things like this where you're always comparing the same value but not against fixed values but "shapes". I think some simple and limited pattern matching would be useful here. ```php $this->handler = function ($var): string { return match ($var) { null => 'null', true => 'true', false => 'false', is string => '"'.$var.'"', default => rtrim(print_r($var, true)), }; }; ``` This would have some significant overlap with the short match proposed here. Combined with the unclear semantics (strict comparison? loose comparison? type error on non-bool values?) makes me unsure if we really need the short match. Ilija -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php