From fc83031a67effa37fb173c2023fcea670fcf3c8d Mon Sep 17 00:00:00 2001 From: Robert Landers Date: Thu, 1 Aug 2024 18:00:51 +0200 Subject: [PATCH] clarity --- drafts/records.md | 22 ++++++++++++++++++++-- published/records.ptxt | 22 ++++++++++++++++++++-- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/drafts/records.md b/drafts/records.md index 7df854c..0fb2cf6 100644 --- a/drafts/records.md +++ b/drafts/records.md @@ -236,7 +236,25 @@ A `record` is always strongly equal (`===`) to another record with the same valu much like an `array` is strongly equal to another array containing the same elements. For all intents, `$recordA === $recordB` is the same as `$recordA == $recordB`. -Comparison operations will behave exactly like they do for classes. +Comparison operations will behave exactly like they do for classes, for example: + +```php +record Time(float $milliseconds = 0) { + public float $totalSeconds { + get => $this->milliseconds / 1000, + } + + public float $totalMinutes { + get => $this->totalSeconds / 60, + } + /* ... */ +} + +$time1 = Time(1000); +$time2 = Time(5000); + +echo $time1 < $time2; // Outputs: true +``` ### Reflection @@ -274,7 +292,7 @@ try { #### ReflectionFunction for implicit constructor -Using `ReflectionFunction` on a record will reflect the implicit constructor. +Using `ReflectionFunction` on a record will reflect the constructor. ``` php $constructor = new \ReflectionFunction('Geometry\Point'); diff --git a/published/records.ptxt b/published/records.ptxt index e494684..2f9cca6 100644 --- a/published/records.ptxt +++ b/published/records.ptxt @@ -199,7 +199,25 @@ echo unserialize($multiple) === Multiple('value1', 'value2'); // Outputs: true A ''%%record%%'' is always strongly equal (''%%===%%'') to another record with the same value in the properties, much like an ''%%array%%'' is strongly equal to another array containing the same elements. For all intents, ''%%$recordA === $recordB%%'' is the same as ''%%$recordA == $recordB%%''. -Comparison operations will behave exactly like they do for classes. +Comparison operations will behave exactly like they do for classes, for example: + + +record Time(float $milliseconds = 0) { + public float $totalSeconds { + get => $this->milliseconds / 1000, + } + + public float $totalMinutes { + get => $this->totalSeconds / 60, + } + /* ... */ +} + +$time1 = Time(1000); +$time2 = Time(5000); + +echo $time1 < $time2; // Outputs: true + ==== Reflection ==== @@ -233,7 +251,7 @@ try { === ReflectionFunction for implicit constructor === -Using ''%%ReflectionFunction%%'' on a record will reflect the implicit constructor. +Using ''%%ReflectionFunction%%'' on a record will reflect the constructor. $constructor = new \ReflectionFunction('Geometry\Point');