Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130717 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 837BF1A00BC for ; Thu, 30 Apr 2026 14:08:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1777558109; bh=KgORNMRO6JR84uPXmd5fDF09v6xXGdjOGicdxh9bCqw=; h=Date:From:To:In-Reply-To:References:Subject:From; b=oDbtL/4jDr1E8s1jkFrhI0Mu44OJlXfD4hiVgWvHdFAv38CzSriHQkMJxgtvZx6Ob +hkhPWiGJEjOJBDL2wpORxxkFBheCt4DhLhxY45ritClEtNG+pjHMOXbhe+4kvTYjc 45dWzBPbEzlrYfnpHums7q8SrBHDzsjxGoV3z99It8Nh4BBZsRHpeLpEYjlDeExScR WqnqyYiMwX/gnQP/Wg8B82jHpX0zBAzh6LMfFO6G8tBtqCIMQXz5CYEP2mu0eSRHCO tJGR6KWYGBymHR+0F2K7/Kc2qgBnb1OFPuQUKpRTuz1+ohHlxvdzm9BqyrBUS0DT5I rsfcNM/f96dRw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 15DA6180061 for ; Thu, 30 Apr 2026 14:08:28 +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.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from fhigh-a3-smtp.messagingengine.com (fhigh-a3-smtp.messagingengine.com [103.168.172.154]) (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 ; Thu, 30 Apr 2026 14:08:27 +0000 (UTC) Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailfhigh.phl.internal (Postfix) with ESMTP id 43C1C140006D for ; Thu, 30 Apr 2026 10:08:22 -0400 (EDT) Received: from phl-imap-02 ([10.202.2.81]) by phl-compute-04.internal (MEProxy); Thu, 30 Apr 2026 10:08:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to; s=fm2; t=1777558102; x=1777644502; bh=HZE95iWg/Bu2l0ow+xbtv 6uPPt4sPTCMSw8ePHjGCT8=; b=NIJhnc9aZshmMjn++8OlZwvZzK6mdE8RNgV62 kwmJ8ejpT9nF73Tvkzn5lftdGajQ2zVUytD2K7LQDTC6SSwmXy7mB1YhnOer7Djb VO+ke7sRRFSt30WCIURsl/gWLzYo9z5eO2kOjxNxfc6qJQn/9JUcGrkVVtjZM58v KksYb5FFqb/Lm0aBvfwK4oWU4/7AmjaqbUfsF9AzxlXpzaDvmTrBIbM8VmIwbyBT vGR1nWj1tQGFsnzZJ3gp5o6bI6jqVPti+P/Ixg4KN6eqElY0eoFsh4s93rF4YvkI GWVeFQcAErBAiVvQ6RSq2Ao0vriycPiCtIHzK7FFcVpVtB5wA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1777558102; x=1777644502; bh=H ZE95iWg/Bu2l0ow+xbtv6uPPt4sPTCMSw8ePHjGCT8=; b=c2UvkGf7oEFBFmdnd +z6xkloFYnPlallP0vTSpGqZeAzM6ahEHe7hgJWldM8bO9ssBM0Q9HzaIrpwcczu mZ9FPffchK5HSDWFfYeOF9GbN3omSMpYrHroKxL8zPJgOMEVemJ0Iwi42NvClD1e H0q7UgH82t5z8hfFlKJ9BKFPQwg3sTNu3zs1iP1LepH8XpdId3O+m8flq4QSw5Wk YkPbJV1grVCsezeaYnjKMzMfFvYYDC5u+MGNYA8fS/Od/cv66fdTylZs1z74BgyZ 0Aea/5NsOkpn56XNUAoUkI3aQ3GtIIaFoCkyCRTi97zO/YPxisYP1NnN6xHcdpAK EsZCg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgdekjeehvdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefoggffhffvkfgjfhfutgfgsehtjeertdertddtnecuhfhrohhmpedfnfgrrhhrhicu ifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomheqne cuggftrfgrthhtvghrnhephfeludehfeefhfevgedvhfefveeltedvieetuedtvdevfeek jeegjeeifeekudeknecuffhomhgrihhnpehstghhvghriigvrhdruggvvhenucevlhhush htvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrhihsehgrghr fhhivghlughtvggthhdrtghomhdpnhgspghrtghpthhtohepuddpmhhouggvpehsmhhtph houhhtpdhrtghpthhtohepihhnthgvrhhnrghlsheslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 067A470006A; Thu, 30 Apr 2026 10:08:22 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 X-ThreadId: AuEUPYrdMaBN Date: Thu, 30 Apr 2026 09:08:01 -0500 To: "php internals" Message-ID: <5686cf60-1920-4f0f-b8f3-9df788f759bf@app.fastmail.com> In-Reply-To: References: Subject: Re: [PHP-DEV] Pre-RFC discussion about adding friendship to PHP Content-Type: text/plain Content-Transfer-Encoding: 7bit From: larry@garfieldtech.com ("Larry Garfield") On Wed, Apr 29, 2026, at 12:30 PM, Daniel Scherzer wrote: > Hi internals, > > I'd like to add support for friendship in PHP. I don't mean friendship > in the PSR-8 huggable way, Aw, but why not? > but rather in the C++ way of allowing access > to non-public parts of a class without needing to use Reflection. > > I haven't started work on implementing this yet, but there is a big > question about how to indicate friendship that I wanted to get some > feedback on. Specifically, should it be added with a new keyword, or > with an attribute? > > Keyword > * matches C++ > * suggests that friends are aspects of the class, like properties and > constants and methods > * but would look a bit ugly if we added support for friends that are > just for specific properties/methods/constants > > Attribute > * matches how other metadata is added to classes > * would make it look cleaner if subsequently support was added for > friendship being applied to specific properties/methods/constants > * would differ from the current builtin attributes in that it doesn't > just add/remove warnings, but changes some functionality > > For a more in-depth explanation of the inspiration and these two > potential approaches, see > https://scherzer.dev/Blog/20260309-php-friends. To be clear, I have not > yet written an implementation, much less the RFC, but I wanted to get > some initial feedback on if people would prefer a new keyword, or an > attribute, for declaring friends. > > -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. 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; } class UserFactory { public function makeUser($name) { $u = new User(); $u->name = $name; // This is OK, because UserFactory is a friend. return $u; } } $factory = new UserFactory(); $u = $factory->makeUser('Larry'); print $u->name; // OK, because public get $u->name = 'Daniel'; // Error, because not a friend. Whether that makes sense to extend to methods, I don't know. --Larry Garfield