Re: Immutability RFC
| From: | Silvio Marijić | Date: | Wed, 16 Nov 2016 14:55:35 +0000 |
| Subject: | Re: Immutability RFC | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-96924@lists.php.net to get a copy of this message | ||
Hi Stepehen,
Since immutable objects doesn't have identity, I'm wondering what would be
best to do in this case when we try to compare them by identity.
Cheers
2016-11-16 15:51 GMT+01:00 Stephen Reay <php-lists@koalephant.com>:
> Hi Silvio,
>
> I don’t see why this wouldn’t simply return false?
>
> Cheers,
>
> Stephen
>
> > On 16 Nov 2016, at 20:57, Silvio Marijić <marijic.silvio@gmail.com>
> wrote:
> >
> > Hi,
> >
> > To anyone who is interested in this RFC. What do you think what behavour
> we
> > should have when you try to compare two immutable objects by identity
> like
> > this:
> >
> > immutable class A {
> >
> > public $a;
> >
> > public function __construct($a) {
> > $this->a = $a
> > }
> >
> > }
> >
> > $a1 = new A(1);
> > $a2 = new A(1);
> >
> > $a1 === $a2
> >
> > If we treat those objects as values then this should return true. But
> then
> > again there might be some confusion because then two operators are doing
> > the same thing. Maybe throw an error ? Suggestions ?
> >
> > Cheers.
> > --
> > Silvio Marijić
> > Software Engineer
> > 2e Systems
>
>
--
Silvio Marijić
Software Engineer
2e Systems