Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110939 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 36147 invoked from network); 11 Jul 2020 15:14:35 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Jul 2020 15:14:35 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id EFCEE1804A7 for ; Sat, 11 Jul 2020 07:06:15 -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=-0.2 required=5.0 tests=BAYES_20,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-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (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:06:15 -0700 (PDT) Received: by mail-ej1-f45.google.com with SMTP id l12so9130034ejn.10 for ; Sat, 11 Jul 2020 07:06:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=/mPA7/B/TUA+iPl1jtxDjsOoz0QKySKJjOM5mrfg8IY=; b=jMO/fNNm7Bqb2+h3oJhfwbOaEi0kXFzjf0XXjc/i5z65t4wUTGV9eIxfi5T8h8yN+d ybxwsOyWW1wnrrMvDsUb8AqK4FEY83MGMgFrah0CT7edH0QeVz1oDc3KDcQPtWrgmNtN B5KLt2H6OqTa1dB6VoNLTwaSAbq9mhZkCqiPaRF6eQZVN5GKwegJ9kXItk9HaVjaWaH+ b/pNJQlRfyZrqL4Sub5qrCsSQ+Vn4B8d2ugad2++LIA46HWaUn1gFFQrgacMO9AmGPjs 9tvsH6CCKZ5dNZIaAmEUA1YozzGrWdLk4q3HonbyR4j6MkhoxXzy+9Nx475ch8UU7RB2 ksSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=/mPA7/B/TUA+iPl1jtxDjsOoz0QKySKJjOM5mrfg8IY=; b=PMCT5GNO8Wo7Kqa97zMDInkr1/ewub43S82bjoHvJVsYUvJuEOEw+iWEm07dzFRg6H 37hAd1qjkMEP+xfYyGZNZSOJV5pie+2qyImsSqS9FuhLWohw9uBILwaLJPFqNe2WPBFG TcuBL2Ii87+22okEMWlP4ExU18kJ+4IBX1yLzF2pEV/VdlK4LyxHa0kOxMqD+C2tIRgm 5IfZ1/RKX55djiGxViy+jlO+fcDuCFdL5l6w3unXk1t1thXkXxN3i2qISmUnUI/idEj3 Cr2+sp/foWSi6R/7FDlztVKzuqgKlS2mvn8zjmyIlqSpqNdyh6QFe55vupbSxjVogB46 K1Cg== X-Gm-Message-State: AOAM531ZloKNEpvABEymJWv71LetIX4vkzam8mVT3Sja9Xbo6ZMSTUvk cq4tVbuXB/Tor/2Cdx6voi4zIn51h6FEwu8RGExX3A== X-Google-Smtp-Source: ABdhPJykv+js1+CQ/r19GAUP/x7RJG6fIJ3OkDDwYh56H8NMaSNTdenu+Oi/jTW4rv29xatpM4Om4XjThuplxtIjXM0= X-Received: by 2002:a17:906:c7c3:: with SMTP id dc3mr52871619ejb.376.1594476373945; Sat, 11 Jul 2020 07:06:13 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a54:3091:0:0:0:0:0 with HTTP; Sat, 11 Jul 2020 07:06:13 -0700 (PDT) Date: Sat, 11 Jul 2020 14:06:13 +0000 Message-ID: To: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Subject: Possible RFC: UniqueInterface that throws exception at refcount > 1 From: olleharstedt@gmail.com (=?UTF-8?Q?Olle_H=C3=A4rstedt?=) 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