On Mon, Dec 14, 2020 at 5:30 PM Andreas Leathley <a.leath...@gmx.net> wrote: > 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)), > }; > }; > ``` >
Or even better with existing syntax: ```php $this->handler = match($var) { null, true, false => json_encode($var), default => \is_string($var) ? "\"$var\"" : \rtrim(\print_r($var, true)), }; I appreciate that this is a specific counter-example to your example, but you picked the bad example. :p -Sara