Hey Olle,

On Sat, Jul 11, 2020 at 4:06 PM 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).
>
> 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
>

I consider the problem problem of singleton enforcement to be solved
elegantly in userland, such as in
https://github.com/marc-mabe/php-enum/blob/v4.3.0/src/Enum.php

Considering that, what does a language-level construct bring in?

Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/

Reply via email to