Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110960 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 32931 invoked from network); 12 Jul 2020 00:32:37 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 12 Jul 2020 00:32:37 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2EC9A180384 for ; Sat, 11 Jul 2020 16:24:23 -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, 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-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (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 16:24:22 -0700 (PDT) Received: by mail-wr1-f42.google.com with SMTP id k6so9409436wrn.3 for ; Sat, 11 Jul 2020 16:24:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:user-agent:in-reply-to:references:mime-version :content-transfer-encoding:subject:to:from:message-id; bh=1OiRnmmR5j7XoToxdowhR/vvcEVJ3GRdpLSaPRxNbSs=; b=GmMEZOiyaKDkB3+9ZuJPsOdJMc6WWiA/U5Gby1ET6qeMg2+E8azzn56wo6Q5RQeTXL BnzrcrgJbxQ2T/n/y6K0UaO9SDkgr9ZBHPEBsqCnjyxpFka5lJ+LB9R6Ztd0YSvXnBHD 8twLBY5gJWHmpmDxYwETW8jhmVpylSCJC/D5cGzjalydIml2HYv/Osslt+Q6D7Dii2Fp tUfn9FLuwWX3LpZh5sLAnyFgvk8udJiInZy10+B489yE1i6KyzsidRg0Jm3hiD3J7drJ 2w+sHXsjtG/QkkYk++ng0SeEyiz0qsB1rvqoeBKnA2bs7B4jO6e4dfLHJ2ozloztlYMT 9lOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:user-agent:in-reply-to:references :mime-version:content-transfer-encoding:subject:to:from:message-id; bh=1OiRnmmR5j7XoToxdowhR/vvcEVJ3GRdpLSaPRxNbSs=; b=UaNyYWdnvr+BUWcZ1XB0QyjsbqdGEdHLRcpROl6jWATce3oKBliBp8SGwz2FZzuz3J W6J8GPD0snGa1dsON9YTcjLqpB8MkTUw4dOzMulQOk1nO9fzNaZ+Hh4czGOnrREN/L8g dg2NSgnK8H+6cT7RzbSHKZLRZVe12KWyh7dNulbel0cXFGjkfAkUsZ9RtMF1Mcd/zcCM 8XXRAEUhfcwiKZ+jOv8PbS50YnHtgi0oi4TlLHZjI5UXF3VkUwsHWoh2NaZeKc78eY0w 4jjNPJXYz7hZnvR6q+N3jbEIGxgaRnk7a6sIRxuxzPAYEPXERpeAI1iRv0/+dmPvC+kT gM6g== X-Gm-Message-State: AOAM532lvD65M0J/IP9S7OM9a0SzUrZCvPY5yEKhvnJqe4J8e5a48StT lgE82hPyf21R9SKG7xi8I9l1DMrx X-Google-Smtp-Source: ABdhPJzKEUjBM2HBo09amFmasewpVubazXGpvwWEiUlzofT/nryZVWkF5IKxb80Yjf9H5m/owqH8nA== X-Received: by 2002:adf:ed8c:: with SMTP id c12mr40058537wro.359.1594509856665; Sat, 11 Jul 2020 16:24:16 -0700 (PDT) Received: from [192.168.0.12] (cpc84253-brig22-2-0-cust114.3-3.cable.virginm.net. [81.108.141.115]) by smtp.gmail.com with ESMTPSA id y17sm17191859wrd.58.2020.07.11.16.24.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 11 Jul 2020 16:24:16 -0700 (PDT) Date: Sun, 12 Jul 2020 00:24:15 +0100 User-Agent: K-9 Mail for Android In-Reply-To: References: <1e39fdcb-16d2-42c3-95cf-507f7b647b50@www.fastmail.com> <3bfb89c5-c8fd-4587-8c1f-8b7bbbaca692@www.fastmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable To: internals@lists.php.net Message-ID: Subject: Re: [PHP-DEV] Possible RFC: UniqueInterface that throws exception at refcount > 1 From: rowan.collins@gmail.com (Rowan Tommins) On 11 July 2020 22:47:21 BST, "Olle H=C3=A4rstedt" wrote: >You're misunderstanding=2E :) Yes, it should be shared, but not with the >same access level as the owner=2E If a dependent class closes the >connection it will cause spooky-action-at-a-distance somewhere else in >the program=2E=20 I think that particular example is solved adequately by destructors: if yo= u know you hold the last reference to an object, you can unset() that refer= ence and the destructor will fire=2E You'd only need the ability to "unfreeze" an object if you were going to m= utate it and then carry on using it=2E > Sorry, it's related to refcount as ownership checking=20 I still don't think those concepts map well=2E If you store two references= to an object in an array, and then unset one of them at random, does it ma= ke sense to say the remaining reference "owns" that value, because the obje= ct now has a refcount of one? As I understand it, ownership in Rust implies not just the *right* to free= something, but the *obligation* to do so=2E That only works if ownership i= s explicitly assigned, rather than being a side effect of other references = being released=2E Thinking about destructors, a better description of how PHP currently work= s might be that the owner of an object is the object itself, and the refcou= nt is a count of how many times it has been borrowed=2E So once the constru= ctor completes, all we can say is that there is at least one "borrowed" ref= erence somewhere in the code; once that stops being true, the "owner" is no= tified, and runs the code in the destructor=2E You could create a wrapper object and have a way to check that its destruc= tor had been called - anything from setting a global variable to holding a = WeakRef and calling its valid() method - but if something *does* hold onto = a reference, there's not much you can do about it=2E=20 I can't think of a scenario where the code that wants to "own" the object = wouldn't end up equivalent to either full immutability (don't mutate it aft= er initialisation because you can't guarantee yours is the only reference) = or an optimised copy-on-write (mutate if you happen to have the last refere= nce, otherwise clone)=2E It would be better for the language to implement t= hose in a user-friendly way than exposing the implementation details of ref= counting=2E Regards, --=20 Rowan Tommins [IMSoP]