Closed bwoebi closed 3 years ago
I'm not a big fan of the syntax honestly. I'd prefer more traditional pattern matching. I'd also argue this belongs to the pattern matching RFC more than the enum RFC.
Yes, I think pattern matching would solve that too, hence #13 to see what they shall and can do.
My thinking there was exactly that. match type
would mean "do an instanceof if it's an object or enum, and a get_type() for anything else." So you could then, mostly as a side effect, do:
match type ($var) {
string => "It was a string",
array => "It was an array",
};
Whether that's ideal or not, I don't know. It's just the best way I could come up with to make match
handle Associable Case Enums without including pattern matching. Although even then we may need to tweak match, as $some_value === $a_pattern_definition
isn't quite cricket, either.
We don't really need this for now.
What are accepted values on the LHS of =>? Is that supposed to work like instanceof, e.g.
match type ($foo) { $enumclassname1 => ...,$enumclassname2 => ..., }
would be valid? And generally applicable to all objects / types (e.g.int
,stdClass
etc.)