Slide 14
Slide 14 text
パターンマッチング
●
isによるパターンマッチング
●
https://wiki.php.net/rfc/pattern-matching
class Point {
public function __construct(public int $x, public int $y, public int $z) {}
}
$result = match ($p) is {
// These will match only some Point objects, depending on their
property values.
Point{x: 3, y: 9, %$z} => "x is 3, y is 9, z is $z",
Point{%$z, %$x, y: 4} => "x is $x, y is 4, z is $z",
Point{x: 5, %$y} => "x is 5, y is $y, and z doesn't matter",
// This will match any Point object.
Point{%$x, %$y, %$z} => "x is $x, y is $y, z is $z",
};