Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110954 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 94142 invoked from network); 11 Jul 2020 20:30:48 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Jul 2020 20:30:48 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 85AAC180541 for ; Sat, 11 Jul 2020 12:22:32 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-io1-f49.google.com (mail-io1-f49.google.com [209.85.166.49]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 11 Jul 2020 12:22:31 -0700 (PDT) Received: by mail-io1-f49.google.com with SMTP id y2so9476935ioy.3 for ; Sat, 11 Jul 2020 12:22:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=RoQmXx1vip/+I+hX+f3eD83MaVZ2aW6KZsEjefwv/MM=; b=TTR6aqyy//dD0WR1//edlOkERd8InBWmPy0MAtrmxkBTyeZ/DQIXJpTq1vAIvHOoQ1 41SZAZhzxzFurwZOm8xoykK0YK7iRfCFnObuopp51pR/5ytgC8Vt5C9sjPJDTkG8lmCp 6XuAOiUMYcxbFuyJP55oz7ib1jljoJbQNO6OBs2vLLuqdTJPJPYCBvAjf1MpG0y1cO6V WsRivPcb/VXi0BfHlGEsCBkpGzkjihHXDJTOU1ZWCfnQd169JWqWmasZBkXUgFjxrtXN O0C8Oordr1vki7XW1ah5bRCr3SLkh1n3Tb9ta6dcbkHpP7jlBP/N4qeqAAkA8H9LYUI1 Dv1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=RoQmXx1vip/+I+hX+f3eD83MaVZ2aW6KZsEjefwv/MM=; b=JcJISZ75kxKcoLvS+7L/YqdusKL/w7N2Bv5yWeNCkBotF85khxd3AVU9Glu4tmuCuv dOuzcyLJ01x2k7nwrlAXPLEheUGptL50D8DVxTmQ/+1gwryNk7SbIpdtud+K1IIY6QuL HHsRYFZmpUHzLL8wqf+/tIdI3RXC92vXszWwY+OtWzC+ZVrlVSaAeOB6X008R6R5fcZU WJPVnlrcaH/OsyRodnwGkaPlIwm0D4dh/XUEtwX+75wiuBZtxt2tnoVPlldxJ6zh1piA Lm9wNDo2hs7gvNgJPLNFvRXH+lK8ioVthtHLCvWBXq4VUX4ANyMML11nCnY7BOi0uLAh JfDg== X-Gm-Message-State: AOAM531itEneDj6hJYrMbl9LBzufeAG+tqkTxzw6HeXAgHFxXkG4qk/P RUPAyrPAq+A3knIp96UYhEEwzeTpujiuuFSH1BA= X-Google-Smtp-Source: ABdhPJzAYJhcJDJqC926LfkkG2gN79bH273kickt++l4G5X1IWhD7KUG7HWVQn2kSDygxTflmafyspOXEeU3QibjKRs= X-Received: by 2002:a02:ccb3:: with SMTP id t19mr84370199jap.122.1594495349677; Sat, 11 Jul 2020 12:22:29 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 11 Jul 2020 21:22:18 +0200 Message-ID: To: =?UTF-8?Q?Olle_H=C3=A4rstedt?= Cc: PHP Internals List Content-Type: multipart/alternative; boundary="000000000000e9e34f05aa2f60b3" Subject: Re: [PHP-DEV] Possible RFC: UniqueInterface that throws exception at refcount > 1 From: ocramius@gmail.com (Marco Pivetta) --000000000000e9e34f05aa2f60b3 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hey Olle, On Sat, Jul 11, 2020 at 4:06 PM Olle H=C3=A4rstedt 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/ --000000000000e9e34f05aa2f60b3--