Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130765 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id B232F1A00BC for ; Mon, 4 May 2026 20:05:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1777925124; bh=oNqoTkalhOm9DTAInG/lnyOxfMoOMzM+mbT2+MnKuAM=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=kT2goi5dwMeQSBmaUlUevTkkUqcwKWRZDDAG8h9GMi0+JtJ24SCtKWVio5Kay9FVU yuaCza6w0GO/w0eT+aM+pgQm7R1iddbEaiihajaRRHyrTsbOn4BD8rEecC8vklWg6d TZUnQz0T7/oYTwV6C66eJzh6StpBxgRB/xbqY6p/EplYTplevUtXkqcPECsxpe5L8n A6BbTLg9cbBvQLJ+P9Igg8SgKe7DXmOXxpl1sTWguZf66td8iQX41GSIU4jAZ+nBI5 j6o0jSdbRsVxfZcXOXEL1bfHGhTx8oomTmRdQKo7/fANDL7IU0LWBVoPhpdxSYNjNV wg2irKJ7P2Zyg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 87847180061 for ; Mon, 4 May 2026 20:05:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-yw1-f179.google.com (mail-yw1-f179.google.com [209.85.128.179]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 4 May 2026 20:05:23 +0000 (UTC) Received: by mail-yw1-f179.google.com with SMTP id 00721157ae682-7bd8cc5ad52so11835707b3.2 for ; Mon, 04 May 2026 13:05:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1777925117; cv=none; d=google.com; s=arc-20240605; b=BLYCIpwW1KllIcoOzKW+EgiG6lyPE84+TdDVBidCbGwzOpOhC5MQDjBFu3IFZi4qIU yhLPrAcy8MRSgsGFE45l8f986UDsHOKyHcWWubGqfDErj1jYSe9JKefAYqBK0pNx+ppT VkTbA7DOv1lyN3Vh/mvA6Ik/r/jgzWjfmqRR/kFOHL3YFl0yR1bYkbOrDdNuVHubIczj zns+ALB3B4HBAGOuWpjpYY5eibUnTA52LA6+LVWQPMX0WiVfAbY6BmDNtsvfZJrMlM3h 5aGCWBXO+l6XDW+cRtEjtfeM5n02SA/QAXEHA5yeLe+GNJQfwcwxaXSwAi4yIjPcsqJF +GSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=fAfXR427GYH7EXYE4UE/tsWVxKrNrVidThmyinGW6fU=; fh=Ofn+XpSLefQyxrNYeqFK5V6BgIEzMTvoqvpJ6/SQfuk=; b=OlbsZEsUa99E2knhDIAcRWj+IhvvUZAnCliF/trcmnc1TSyqg2x7lIOgvtlWc59Fkk Qmj/m2j1pVKuLWcNPILWhaB3ghU5n1SdexhaNcx0uXhqAwmaJLOGS98YyyyZiGa7fXmn f6zjVQuzAGkChP5NJ7/5ydKMl2bHVwMcXMwL52GaZ92A3eikUscMgeX5lmhjIDj89oK3 XXFQwWSgn+qHB2jXHMHzQ5qAv279hiBnHDfHcmO6ZJCIoWzvCIWPobqLMOPI9OieUEL8 lZdPtLRrRSAHSTxAlKmHZXr5HwafFMmbPqlHq2ocO2VZin+o27zPqpwcqa5yTr1D39I/ v3Yw==; darn=lists.php.net ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777925117; x=1778529917; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=fAfXR427GYH7EXYE4UE/tsWVxKrNrVidThmyinGW6fU=; b=jM2t6nTjYYm3uBYQ1BZ7kJsVFzQ6SJRYqiMtYKJYeamd80h6BvxNfUw6oh+uCQq8Ch BZjNcZpoBNvDQJX4m6YulR0KuHV2KxRcb2IoY/yg4XjzfSv8LDQ1mMpGtjlZvaHW+BnY urYP1YOWPvghlFpn5jkzaGDTIAf0Xy9T5RM2sUtwHZk4FFb7avTJih3D9d5NHGDnhUjJ kNtaJdGPUZToMEPxTehPYTqKyfPDswZFXQ9b7xWLQJhpSsje5bTUDrH/4ok+v/nM3Yfy WEi6SSOR/PhKZY30SM6C0ka9uQrpyzQYKSsyob5MBzIvAaffxVMXEY923l3z2W5GvxCn kl/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777925117; x=1778529917; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=fAfXR427GYH7EXYE4UE/tsWVxKrNrVidThmyinGW6fU=; b=lYryxtBM24Xp5kEJESVDMFLJuENnLkyu1dbH0+OtaQM4R/qb6kt+/KEnXCnbJ/sQ5E VQJYNF5HKevMICx5j8RZuhBQvEFAdfJjkA8GcBLQz6vR2mwrjEkYJiZ/N6iB6jDdR+/E ueV4mb2er53Ld+2s72T5Cb149mVHNfD6I8Ibf76sHcXHJ4JtaIECHnCrvGc4qUtXNxaj FC3WC9z/TG/oAh/dP4ACGL3XuQXv9aIoqBuKrnN2z8x3LgKFBYOzQ7KOmWtw8KY0ZIpM SfT2p4m6mN4F7MAa1OpJY1b7zdXo8S+pwXSTtRhfWzO35IfGe8xnYSsZ1j4p8aT1I9ss hNow== X-Gm-Message-State: AOJu0YxTWzgorQ4KwG73TDf1ykOoTH3HQLcMFii2M5kn2rirgUi/KgmW Al6jPsbwnLFl4N+6QD9FcmdyH9Ss5yuds0x/QcdS/iaJlxEb+4YKevVFFkKiEBDC42wXLHVIuFJ mfjBPtFEvKBtN4nI453UxVPEiS8pT7U5GsA== X-Gm-Gg: AeBDievfSmadzm9axjMQtoLka/GmiOFYjlDqRMcno9/VTOYFA6F2Zm5Tc4Jln8lcsHM Cx9wAetwvSbnhI2hb3b69hCe6Ls2gRk3turJKByBcYOXiP/DK6Hn4wyXtuc3nqGbW40y2BHPRCb NN8KX2bBPOdkiZkX6YZ/TxjiNJ3hrvbUoL0ULPIldsEnlfbfD8aebVYPJREtBxH2/Mhz/5+4EhJ ZWxyOrks6Ys6dh0dssqLhKSHKYIU6drso7TV4Ooo/kta0nji2/gn4x3GTddcdb5pIgBuIwyTs57 iKHicsU1Kz8yCP/EcwOYz1JGUn08 X-Received: by 2002:a05:690c:c149:b0:7ba:ee75:f115 with SMTP id 00721157ae682-7bdac4e2ddfmr2423607b3.4.1777925117497; Mon, 04 May 2026 13:05:17 -0700 (PDT) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: <5686cf60-1920-4f0f-b8f3-9df788f759bf@app.fastmail.com> In-Reply-To: <5686cf60-1920-4f0f-b8f3-9df788f759bf@app.fastmail.com> Date: Mon, 4 May 2026 13:04:43 -0700 X-Gm-Features: AVHnY4Kv0qzmTgnv5H9AxovpgMWdvqCYZXYzud6jL7oqdQzhABzSwyOTxEdLqFM Message-ID: Subject: Re: [PHP-DEV] Pre-RFC discussion about adding friendship to PHP To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="00000000000010d2450651037398" From: daniel.e.scherzer@gmail.com (Daniel Scherzer) --00000000000010d2450651037398 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, May 4, 2026 at 12:50=E2=80=AFPM Larry Garfield wrote: > On Wed, Apr 29, 2026, at 12:30 PM, Daniel Scherzer wrote: > > Hi internals, > > > > I'd like to add support for friendship in PHP. > > > > -Daniel > > There was a lot of related discussion around module/package/file > visibility not too long ago that is also worth reviewing. Currently I am > highly skeptical of friend classes, as I believe module-level visibility = is > more useful than class-level, in general. > I think that perfect should not be the enemy of good, and this also lays the groundwork for namespace-level friends in the future. We shouldn't wait for a potential future "module-level visibility" if we can have friends now= . > > That said, were we to go this route, I agree that keywords would be the > way to go for the reasons given in the blog post. Also, there's some > plumbing already i place via aviz, at least for properties. In concept, > the following should be possible: > > class User { > friend UserFactory; > > public friend(set) string $name; > } > I think having friends that can access everything is more helpful than a new level of visibility - if you declare a class as a friend you already know that the class exists and wants to access private implementation details, so you can trust it to upload the class invariants. -Daniel --00000000000010d2450651037398 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

On Mon, May 4, 2026= at 12:50=E2=80=AFPM Larry Garfield <larry@garfieldtech.com> wrote:
On Wed, Apr 29, 2026, at 12:30 PM, Daniel Sche= rzer wrote:
> Hi internals,
>
> I'd like to add support for friendship in PHP.
>
> -Daniel

There was a lot of related discussion around module/package/file visibility= not too long ago that is also worth reviewing.=C2=A0 Currently I am highly= skeptical of friend classes, as I believe module-level visibility is more = useful than class-level, in general.

I = think that perfect should not be the enemy of good, and this also lays the = groundwork for namespace-level friends in the future. We shouldn't wait= for a potential future "module-level visibility" if we can have = friends now.
=C2=A0

That said, were we to go this route, I agree that keywords would be the way= to go for the reasons given in the blog post.=C2=A0 Also, there's some= plumbing already i place via aviz, at least for properties.=C2=A0 In conce= pt, the following should be possible:

class User {
=C2=A0 friend UserFactory;

=C2=A0 public friend(set) string $name;
}

I think having friends that can acces= s everything is more helpful than a new level of visibility - if you declar= e a class as a friend you already know that the class exists and wants to a= ccess private implementation details, so you can trust it to upload the cla= ss invariants.

-Daniel
--00000000000010d2450651037398--