Created
November 5, 2020 14:45
-
-
Save iluuu1994/5998bdcd4e0aeea7d5258096e58c940e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| data class Point( | |
| int $x, | |
| int $y, | |
| ); | |
| // Compiles to | |
| class Point { | |
| public initonly int $x; | |
| public initonly int $y: | |
| public function __construct(int $x, string $y) | |
| { | |
| $this->x = $x; | |
| $this->y = $y; | |
| } | |
| public static function __isIdentical(Point $lhs, Point $rhs): bool | |
| { | |
| return $lhs->x === $rhs->x | |
| && $lhs->y === $rhs->y; | |
| } | |
| public function __deconstruct(&$x, &$y): void | |
| { | |
| $x = $this->x; | |
| $y = $this->y; | |
| } | |
| } | |
| $point1 = new Point(1, 2); | |
| $point2 = new Point(1, 2); | |
| $point1 === $point2; // true | |
| in_array($point1, [$point2], true); // true | |
| [$x1, $y1] = $point1; // $x1 = 1, $y1 = 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment