Skip to content

Commit

Permalink
clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
withinboredom committed Aug 1, 2024
1 parent 97057b4 commit fc83031
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
22 changes: 20 additions & 2 deletions drafts/records.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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');
Expand Down
22 changes: 20 additions & 2 deletions published/records.ptxt
Original file line number Diff line number Diff line change
Expand Up @@ -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:

<code 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
</code>

==== Reflection ====

Expand Down Expand Up @@ -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.

<code php>
$constructor = new \ReflectionFunction('Geometry\Point');
Expand Down

0 comments on commit fc83031

Please sign in to comment.