Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110950 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 71975 invoked from network); 11 Jul 2020 18:19:05 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Jul 2020 18:19:05 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 29746180508 for ; Sat, 11 Jul 2020 10:10:48 -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_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (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 10:10:47 -0700 (PDT) Received: by mail-ej1-f50.google.com with SMTP id w6so9559164ejq.6 for ; Sat, 11 Jul 2020 10:10:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=rgi9mhvk1XsR3AmzdaK3NFkt2VM8b+E3O3yyE3tSKXE=; b=hb+kLHV217igcrVHl9CUusC3CIfvK70mVDGDiZKfUe/s5umzaAMcjVHAmth/nrNDtA uYIZB00zkvvb7DyWPYRaOQw5wYWilfKWxAVOzm4Z+xcvG6BlovlFmtCPZi/uyOciFMH3 SdYYlaw1jCA111p/0+Fp0x54EmxSeZYvAAHZI2UVDLolvPF9Vqx/i92IfTeTufe+3lj6 hAw5a8T1BSMQd351SEFfPeGWJqqYLcneY07qHcIGEQ61cfY73qXRRzM+9U5ZGE7/r3es w37PX94p0UaJqN6LgJ11RTwmCn5DvXn6omidCnx/PVmjl8ru0Pgn46rrinv68h9+oQO8 FovQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=rgi9mhvk1XsR3AmzdaK3NFkt2VM8b+E3O3yyE3tSKXE=; b=MdgptXO3suSxQzrDTWNtmglbdY5H3Wef6iV6+rAnW9aA8kog60lxz6d7MY/42K8KJr 4iEiPC3cs21f3WW8ZV7UEBoO1muC0EgyFMFZr7bfqb8gVAOxNUQXEcx7ruk/FYGh2mVP 9qneWWhfRRjfmpKRKg/EPqnwAGAvf0lzzIfJ4khLUTWygpAyCO/tln0IbYnvERm72ru2 VDaYsbhpbY3X4Q1Tk0FKJ6lT/POKjhvSwlHKFiiie0p3Emi+lz9moTccsu43cSLAnBVO wUjECFMVz3pMxScIgajT9bHOZqhJqeEIF7Wbj/Acr9lG/SnTXEqC5fGDidnwGEgYE3Qi J2fg== X-Gm-Message-State: AOAM530x8ukYlTO2FKDISbtQEjzKCnNaeFhCHpmsWfySZAls+uq4KwTZ DhgTyGdgusqQyzdWJoHgWxoL4HHO0hX+5YcZfUU= X-Google-Smtp-Source: ABdhPJzIuk0lWTeYJQjaHI+V/T4TuGjAL8UDEFGfjY9KqeVfS+kjNHf0uq+UKytjCl9VknongX7k4bVTW+WMDZLzEWE= X-Received: by 2002:a17:906:c40d:: with SMTP id u13mr64157743ejz.519.1594487444183; Sat, 11 Jul 2020 10:10:44 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a54:3091:0:0:0:0:0 with HTTP; Sat, 11 Jul 2020 10:10:43 -0700 (PDT) In-Reply-To: References: <6D442090-FA51-48A9-A07D-F27F5EF6FC0A@gmail.com> Date: Sat, 11 Jul 2020 17:10:43 +0000 Message-ID: To: Rowan Tommins Cc: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Possible RFC: UniqueInterface that throws exception at refcount > 1 From: olleharstedt@gmail.com (=?UTF-8?Q?Olle_H=C3=A4rstedt?=) 2020-07-11 16:50 GMT, Rowan Tommins : > On 11 July 2020 16:13:24 BST, "Olle H=C3=A4rstedt" > wrote: >>Yes, the point is to be limiting. :) Just like with immutability, you >>apply certain limitations to avoid access abuse. > > > Taken to extremes, this is the "secure a server by encasing it in concret= e" > strategy - the hard part about designing useful limitations is not the pa= rts > you want to make impossible, it's the parts you want to remain easy. > > There is a reason Rust has a whole set of mechanisms for managing ownersh= ip, > not just a single "mine/yours" split, because they allow the programmer t= o > express what they want to do with the object. > > >>Regarding "freezing" an object, I actually already wrote about this in >>a blog post, using dependency injection as a use-case, and a trait to >>add a method to check the refcount: >>http://olleharstedt.github.io/php/2020/07/08/immutable-at-borrow.html > > > The difference in my mind between freezing an object and tracking ownersh= ip > is that "frozen/unfrozen" would be an explicit state set on the object, n= ot > a measurement that differs as it is used. So either the user says "freeze > $object", and it is then immutable for the rest of the program, or some > point after construction implicitly freezes it with the same effect. > > This eliminates the dependence on tracking ownership or giving meaning to > the refcount, because no matter how you received the object, you must no > longer cause it to be mutated. > > It also has much lower performance impact. Even the automatic form can > probably be performed by the compiler - e.g. if "new" was called in this > function, insert a call to "freeze" before the first time the object appe= ars > as a function parameter > > Regards, > > -- > Rowan Tommins > [IMSoP] > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php OK, but then there's no need for any compiler changes - just make trait CanBeFrozenTrait, add a property $isFrozen : bool, and then make sure all methods check this property and throw an exception if it's violated.