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).

Rational: Immutable objects are considered "easier to reason about"
and generally more safe, and as a way to avoid
spooky-action-at-a-distance. I argue that mutability is totally fine
as long as it's not *being shared*. Currently, there's no way to
enforce this in PHP, *but* PHP has a refcounting GC which could do
this. This would be a more performant alternative than to build lots
of immutable objects using $obj->whereSomething('bla') constructs.

Cons: If PHP switches to tracing GC, it will be unusable.

What do you think? Should I write it down as an RFC? Implementation
should be straight-forward, assuming refcount is manipulated at a
single place in the source.

Regards
Olle

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

Reply via email to