Re: Possible RFC: UniqueInterface that throws exception at refcount > 1
| From: | Olle Härstedt | Date: | Sat, 11 Jul 2020 14:39:27 +0000 |
| Subject: | Re: Possible RFC: UniqueInterface that throws exception at refcount > 1 | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-110942@lists.php.net to get a copy of this message | ||
Thanks for your answers!
Yes, it would be a dynamic uniqueness system, kind of.
Another more flexible alternative would be to add magic methods at
refcount = 1 and refcount > 1, possibly __owned() and __shared(int
$refcount), for classes that implement a TrackReferencesInterface or
similar. But this would need to do ~0 performance hit if not used,
don't know if possible.
Olle
2020-07-11 14:29 GMT, Chuck Adams <cja987@gmail.com>:
> On Sat, Jul 11, 2020 at 8:06 AM Olle Härstedt <olleharstedt@gmail.com>
> wrote:
>>
>> Dear internals,
>>
>> I'd like to discuss the concept of ownership in PHP, from the point of
>> view of a new interface UniqueInterface (or SplUniqueInterface or
>> something), which will throw a UniqueException if refcount > 1.
>>
>> Use-case: Mutable objects that cannot be shared (without (deep) cloning)..
>
> I don't think you want to do this on refcount, since that would
> prevent even passing it to another function or using it in any number
> of expressions. What would make more sense to me would be hooking
> into copy-on-write, which would also be a slightly less hot code path
> than reference counting (but still a pretty critical one).
>
> It almost sounds like a uniqueness type, something well beyond the
> capabilities of PHP's type system (and most others).
>
> --c
>