Re: [RFC][Concept] Data classes (a.k.a. structs)
| From: | Bruce Weirdan | Date: | Tue, 02 Apr 2024 18:51:49 +0000 |
| Subject: | Re: [RFC][Concept] Data classes (a.k.a. structs) | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-122890@lists.php.net to get a copy of this message | ||
On Tue, Apr 2, 2024 at 8:05 PM Ilija Tovilo <tovilo.ilija@gmail.com> wrote:
> Equality for data objects is based on data, rather than the object
> handle.
I believe equality should always consider the type of the object.
```php
new Problem(size:'big') === new Universe(size:'big')
&& new Problem(size:'big') === new Shoe(size:'big');
```
If the above can ever be true then I'm not sure how big is the problem
(but probably very big).
Also see the examples of non-comparable ids -
new CompanyId(1)
should not be equal to new PersonId(1)
And I'd find it very confusing if the following crashed
```php
function f(Universe $_u): void {}
$universe = new Universe(size:'big');
$shoe = new Shoe(size:'big);
if ($shoe === $universe) {
f($shoe); // shoe is *identical* to the universe, so it should be
accepted wherever the universe is
}
```
--
Best regards,
Bruce Weirdan mailto:weirdan@gmail.com