Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110944 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 49045 invoked from network); 11 Jul 2020 16:04:54 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Jul 2020 16:04:54 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 424BF180508 for ; Sat, 11 Jul 2020 07:56:35 -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-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (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 07:56:34 -0700 (PDT) Received: by mail-wr1-f48.google.com with SMTP id s10so8709531wrw.12 for ; Sat, 11 Jul 2020 07:56:34 -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=lf6yvsD7h69iWHiX1S3con96PDE65+G1EljmrLff+c8=; b=PQ5dJUs3cmaAcrLuzZpDGXTTqx5mh+PQ7IkpAhG9mqAJt2N+gREQ4eU3QYD2jUudPc eQUGE9Tx8n5vAwqVWKrJ8PIlq0C6Q1VWbrji+BhKo+TlVUOwVPnkZnzWu1QHBqNBPLr/ t5VEGUj86SCjbSH6NvB7ppUpYyLHQsQ9WFabLBl86aullueGUB76utqlzJJeG2bspQ3P fwKlLFCI+133ebenBnCeSE9qpVyG50fZQobddAVmJZel0VGVHG138+lU713nUb3dvf0M FBX88s89AUhfmUj5lqn0i1tysbbLT8hedm7id5F20fTSprfIrgGjN1OtC6TGkAqBJuJe 5mbg== 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=lf6yvsD7h69iWHiX1S3con96PDE65+G1EljmrLff+c8=; b=pdx/8yiENb+l4WYMnt6+/8/CT0aVS7HQDVof1fer3et2YP5v7afe40sdXNqQIfuTvM 4rnRGweBEcRJGsZQC0b9ksbJONxPQSKlMA8eqt220H0H0+Y4f9EE6KokOSHYvT0m1vsi HXFAzzqloTALetY+L4guPw0ZR29HAlKeHa2X30sIvYhm+eXHmVcN3QkcflBaK9+Ym0WN ZkyvSg3nMzJSx5GqgW50L2o7E8v9/63VrGafQDWd/5T9RewXJD+Os7Dqr6J5wUNvGK2W LVZDfrI3vcxY66hv0hJZaOr0CfLiKBWraseUaf14aFVwIssmjr+Au2/IqO+L8xluDuct ozQg== X-Gm-Message-State: AOAM533KWgFIoAwMqPVNbrRab3ceoDcv9KLzcNG7vA0oLT4/mJowTElq sn6fP+lOi4qzkoedxdFivrD+wbks X-Google-Smtp-Source: ABdhPJwjNyXNFNsv7x6xh3bctrT6OEAsgmF43gmnbzyW+V1F0+yHl2ltQByroXNPUYhHgPFn3w35Yw== X-Received: by 2002:a5d:6a06:: with SMTP id m6mr71690310wru.321.1594479391848; Sat, 11 Jul 2020 07:56:31 -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 r1sm14656915wrw.24.2020.07.11.07.56.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 11 Jul 2020 07:56:31 -0700 (PDT) Date: Sat, 11 Jul 2020 15:56:29 +0100 User-Agent: K-9 Mail for Android In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable To: internals@lists.php.net Message-ID: <6D442090-FA51-48A9-A07D-F27F5EF6FC0A@gmail.com> Subject: Re: [PHP-DEV] Possible RFC: UniqueInterface that throws exception at refcount > 1 From: rowan.collins@gmail.com (Rowan Tommins) Hi Olle, On 11 July 2020 15:06:13 BST, "Olle H=C3=A4rstedt" wrote: >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=2E It's an intriguing idea, but I'm not sure how well it would work in practi= ce=2E Maintaining a strict refcount of one means never passing the value to= another function or scope, which seems very limiting=2E=20 It would also run into the usual problem PHP has that everything is determ= ined at run-time, so every time you pass an object anywhere, the engine wou= ld need to check it wasn't marked in this way=2E That could be avoided if i= nstead of a special type of value, this was a special type of variable; the= n it could probably be determined at compile time that you were passing a "= local only" variable to another scope=2E >Use-case: Mutable objects that cannot be shared (without (deep) >cloning)=2E This is another tricky aspect - like enforcing deep immutability, it impli= es some recursive constraints which are easy to enforce for scalars, but tr= icky once you look at things like arrays, which can contain references, obj= ects, other arrays, etc=2E As described, the user would have to manually perform a clone whenever the= object was passed anywhere, even if they weren't mutating it anywhere=2E I= f you let the language do that automatically, you can use an automatic copy= -on-write system, like PHP already does for arrays (and, funnily enough, PH= P 4 did for objects)=2E Alternatively, you can make the object purely immutable once it has passed= out of its initial scope, or once a special function has been called to "f= reeze" it=2E This would be an interesting solution to the "modified clone" = problem of full immutability (how to implement withFoo methods), since any = "frozen" object could be cloned to get a mutable copy, which would be froze= n before passing on=2E Regards, --=20 Rowan Tommins [IMSoP]