Possible RFC: UniqueInterface that throws exception at refcount > 1

From: Date: Sat, 11 Jul 2020 14:06:13 +0000
Subject: Possible RFC: UniqueInterface that throws exception at refcount > 1
Groups: php.internals 
Request: Send a blank email to internals+get-110939@lists.php.net to get a copy of this message
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

« previous php.internals (#110939) next »