Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110957 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 13109 invoked from network); 11 Jul 2020 22:34:37 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Jul 2020 22:34:37 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 20F0F180533 for ; Sat, 11 Jul 2020 14:26: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=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, RDNS_NONE,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from out3-smtp.messagingengine.com (unknown [66.111.4.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 11 Jul 2020 14:26:22 -0700 (PDT) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 12F1C5C00AC for ; Sat, 11 Jul 2020 17:26:12 -0400 (EDT) Received: from imap26 ([10.202.2.76]) by compute7.internal (MEProxy); Sat, 11 Jul 2020 17:26:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=tFUAiqDUmVzqmlDB71E/7/IFmgaWFivsiJG7YVmGS Eg=; b=Ylb0Azc4ck9m6Liy1+RodtDaW7xQvxYHAstfN3VUhyhTkJgB2TDo8NVn/ tyPied6wcmgUoXXN5CcGRAPPNJPLWwe5QhuaXybL80VOuiBOjax/P0YeySiRF0Kt 0QX6Lb6nErgZ4zw1lI8yRnDNsshZ37KkfQb0ylto+HjexYis8uK4buZXg1B6Ni98 LVuiNuzTDJgi2Z2DlxHv+o17K8m/HbHaYAA+h5YDj5VgdXciTx/bmbQxpZaS8uMv KJ6QdwYL9q9IE2M4OXToFriiOnTWg0uD1YAr4imQSHOkbWBBZZ2s+082TPHYD6PO GeWU1KNPW/M98fpR0H9JPjbyQnGrQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduiedrvdefgdduieegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnheptdejgefffeeftefhlefhudfhgeehvdelgfelheef udeghfegvdfhiefhtdetudfgnecuffhomhgrihhnpehphhhprdhnvghtpdhphhhpqdhfih hgrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhho mheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 4F0C914200A2; Sat, 11 Jul 2020 17:26:11 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.3.0-dev0-613-g8a73ad6-fm-20200709.001-g8a73ad6e Mime-Version: 1.0 Message-ID: <3bfb89c5-c8fd-4587-8c1f-8b7bbbaca692@www.fastmail.com> In-Reply-To: References: <1e39fdcb-16d2-42c3-95cf-507f7b647b50@www.fastmail.com> Date: Sat, 11 Jul 2020 16:25:50 -0500 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: =?UTF-8?Q?Re:_[PHP-DEV]_Possible_RFC:_UniqueInterface_that_throws_except?= =?UTF-8?Q?ion_at_refcount_>_1?= From: larry@garfieldtech.com ("Larry Garfield") On Sat, Jul 11, 2020, at 4:04 PM, Olle H=C3=A4rstedt wrote: > > I think that would do a far better job of addressing the > > shared-mutable-state issue than reference counting, because it attac= ks the > > root problem rather than a symptom. > > > > --Larry Garfield > > > > -- > > PHP Internals - PHP Runtime Development Mailing List > > To unsubscribe, visit: https://www.php.net/unsub.php >=20 > I think freezing objects might be better fit for my imagined use-case.= > The only problem I see is that you can't really unfreeze them. Imagine= > a database connection that only can be open/closed at refcount =3D 1: >=20 > ``` > $connection =3D new OwnershipConnection(); > $connection->open(); > $ps =3D new PostService($connection); > $ps->updateAllPosts(); // Throws exception if $connection->close() > $connection->close(); > ``` >=20 > With freeze, you could also do >=20 > ``` > $ps =3D new PostService($connection->freeze()); > ``` >=20 > to ensure it's not closed by mistake. But then you couldn't close the > connection at all, except in __destruct. >=20 > Especially, CoW for objects (at opt-in) is not a replacement where > ownership is supposed to replace immutability for performance reason, > e.g. creating a separate immutable database connection for every class= > that uses it. >=20 > Immutable builder are already part of PSR, e.g. here: > https://www.php-fig.org/psr/psr-7/ >=20 > I have to wonder how reasonable this is, when freezing or ownership > are also relevant solutions, with different trade-offs. >=20 > Olle A database connection is the textbook example of an object that *should*= be shared; giving a separate connection to every service object is only= going to waste time opening multiple connections and waste open connect= ions. Please don't do that. Your example seems directly contrary to the goal you're describing. --Larry Garfield