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 <cja...@gmail.com>:
> On Sat, Jul 11, 2020 at 8:06 AM Olle Härstedt <olleharst...@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
>

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to