On Tue, Dec 15, 2020 at 1:37 PM Andreas Leathley <a.leath...@gmx.net> wrote:

> ```php
>
$this->handler = match {
>           null === $var => 'null',
>           true === $var => 'true',
>           false === $var => 'false',
>           is_string($var) => '"'.$var.'"',
>           is_callable($var) => 'callable',
>           is_object($var) => get_class($var),
>           default => rtrim(print_r($var, true)),
> };
> ```
>
>
I saw a proposal connected to match about a year ago that included type
based matching, something like:

match ($var) {
  true => 'true',
  false => 'false',
  instanceof int => "int($var)",
  instanceof string => "\"$var\"",
  instanceof object => get_class($var),
  instanceof DateTimeInterface => $var->getTimestamp(),
  default => rtrim(print_r($var, true)),
};

That might satisfy at least one of the use cases in a general way.


> I do like Nikitas idea to make it a TypeError for non-bool matches.
>
>
 Yeah. Within the context of this featurette, that's something we should
include in the proposal.  If you're doing a match(true/false/other-literal)
(explicitly or implicitly) then your cases should be commensurately more
well constrainted.

-Sara

Reply via email to