Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126922 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 qa.php.net (Postfix) with ESMTPS id 2FA6D1A00BC for ; Mon, 24 Mar 2025 16:09:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1742832401; bh=E8aFwprHIwzzXzucOrlyOp/mRFsW7WrXCjInoymueh8=; h=Date:From:To:In-Reply-To:References:Subject:From; b=E7a6CBHxzIcpQkSLTxKvE9VJHe8INpSfI+u+oXs4tV8xcBrgIdfHewKacMdXuHbze pzjIn5Jr0xJoi16431RKGU14CmItnPj0UuNQgcb2j2ApBKDfW9Q8HCow/nnMgKVnKo 9RFJe4wgM5a5Pys8kyeWYpZdf4iZpcvgC2onwx4OVWIdtP3e24y+zZwIreDOUk1+yA dJvaTeP0OEJ/K17VO1UAld9dHJ3To4uWbIr4tZUHEcJRn6QJj2v409ZQ3HE24JCU4q Ey9FalMK9rhq9vHk1T8VDPI4DyltFEEjzvRvLKyG8LcdkUt6hNTvDHz+CaPKbgJCmx irKzNKuGSbr6w== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BBA96180084 for ; Mon, 24 Mar 2025 16:06:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,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.0 X-Spam-Virus: No X-Envelope-From: Received: from fhigh-a6-smtp.messagingengine.com (fhigh-a6-smtp.messagingengine.com [103.168.172.157]) (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, 24 Mar 2025 16:06:39 +0000 (UTC) Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfhigh.phl.internal (Postfix) with ESMTP id B86871140167 for ; Mon, 24 Mar 2025 12:09:08 -0400 (EDT) Received: from phl-imap-06 ([10.202.2.83]) by phl-compute-04.internal (MEProxy); Mon, 24 Mar 2025 12:09:08 -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=1742832548; x=1742918948; bh=wMQo9vLBWGurTdSyAR2EP FJvpvWLnO+jmsA+Ur/SqAA=; b=eJAC2mJiXArQ8acSwbXMXcwf82ph2zVGRtoeG kDYPdciX0jr9JvRiO7h7d8aW7pXRDSgIfcskQOXBp96bFj/cXqZHkPGfr5YIUrVS iKi1sOq+8i0v6y6Ty2MLW+ZIM4TieYbu6ycOrLxAOv36PDOouXpHpIAVPTpyu/nU +AnvO23duSyylquqR7HNjLDubJGdhCIcyTbTIyUYv9NLvjjFLhJHatQgbs6mOcpA vvfFa73g9EtMTK0fTlY/a/EfI+LlfkLd3d2S71atMa6R+JmSwJ6721VSiv6CLRwn rtOQXZzI9X6Ii181hSvO9csMbUIl/6rnFel4GvnGaAHov+hpQ== 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=1742832548; x=1742918948; bh=w MQo9vLBWGurTdSyAR2EPFJvpvWLnO+jmsA+Ur/SqAA=; b=ikXu5sXylOJpKPw7W MR6gdm48nKiF3yNAt9MExJ9nZXbWnphOLfhvLLMfEqA1hf6FEKAgN2Nqhh7tAsuF aCL6o6+kKj/fYVh7cQYgq+r8x7UORhs+OQ871LU7WDD7csYLE1g0boa3qTW09AcZ iTf+cMBhYDcg55Q5ebrO3KtXfkNdp6SUmNXj4nkI/IMfTqU76WI3Y6JYfCQViX/5 K+KqYZvSsngcyDl1upt3z8m3P0WlwpJsVXoCOpLeT18sBB38wk2x3je4jIweZ+fF 5nQzTHmKWMdhxn54HbTVooOQI7ab7gtVWQNpiAL1YduwL20gVW6ZGggkcD4WNPpe HDIsw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduiedtvdduucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhepofggfffhvffkjghfufgtgfesthejredtredt tdenucfhrhhomhepfdfnrghrrhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrh hfihgvlhguthgvtghhrdgtohhmqeenucggtffrrghtthgvrhhnpefgteffueduudeiuddv ffeiuddtudehfeegjefhheeliefhieelvdegjeeggfehheenucffohhmrghinhepghhith hhuhgsrdgtohhmpdhsphgvtgdqsghrrghinhhsthhorhhmrdhmugenucevlhhushhtvghr ufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrhihsehgrghrfhhivg hlughtvggthhdrtghomhdpnhgspghrtghpthhtohepuddpmhhouggvpehsmhhtphhouhht pdhrtghpthhtohepihhnthgvrhhnrghlsheslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 6B9D929C006F; Mon, 24 Mar 2025 12:09:08 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 X-ThreadId: Td94a63d0143dd548 Date: Mon, 24 Mar 2025 11:08:47 -0500 To: "php internals" Message-ID: <21719220-4b27-43cc-b387-ff803419de59@app.fastmail.com> In-Reply-To: References: <3e4ba7ea-a154-452d-abfc-05ef1322fade@app.fastmail.com> <782d76d9-711a-4cee-ae0e-fe0d69973f53@app.fastmail.com> <48dce917-d147-456b-9f03-c7e23411adff@app.fastmail.com> <8a16b81c-7dab-4523-a352-76ba0cb4e771@app.fastmail.com> <9c4ac301-dfb2-49da-90e5-37a2824fc4e3@app.fastmail.com> <5b1e6d70-a1c9-455c-93d3-6b22cf1fef11@app.fastmail.com> Subject: Re: [PHP-DEV] RFC: short and inner classes Content-Type: text/plain Content-Transfer-Encoding: 7bit From: larry@garfieldtech.com ("Larry Garfield") On Mon, Mar 24, 2025, at 3:47 AM, Rob Landers wrote: > On Sun, Mar 23, 2025, at 16:17, Larry Garfield wrote: >> I've been following this thread with interest, and at the moment I'm honestly undecided. I certainly see the use cases for this functionality (whatever it gets named), but as a practical matter it sounds like it introduces a lot of extra clunk and complexity. And it seems like the use cases could be addressed as well with either fileprivate or module-private. (The former being considerably less work.) >> >> So, how would nested classes compare to fileprivate, in terms of ability to solve the problem space? As I understand it, the goal is: >> >> 1. Classes that can be instantiated only by the class that uses them. >> 2. But can be returned from that class to a caller and reused as appropriate. >> >> The autoloading question (loading a whole file for just an implementation detail value object) is not one that carries much weight for me, as that's a user-space question, not an engine question. (Nothing in PHP itself says you cannot put 20 3 line classes or enums together in one file. It's just PSR-4 that says not go. Even composer would allow it if configured properly) So how would the less-complicated alternative compare? >> >> --Larry Garfield > > Hey Larry, > > I think file-private would/could be useful, but that only limits you to > a "private" scope, which severely hampers what you can do with it. If > we went with "module-private" (rhetorical question: what is a module?), > but then you wouldn't be able to have "private" scope. When I say module scope, I'm referring to something along the lines that Arnaud and I were exploring a while back. tldr, "cluster of files with a common namespace root, which can get loaded together." It was mostly about performance, but did offer module-private as well, with some nice potential. At the moment it's stalled out on "there's nasty hard edge cases and we're not sure if it's worth it" concerns. Concept brain dump here: https://github.com/Crell/php-rfcs/blob/master/modules/spec-brainstorm.md Code exploration from Arnaud here: https://github.com/arnaud-lb/php-src/pull/10 Still well short of RFC state, of course, but provided for context. > With nested/inner classes, for example, you can put a protected class > on a class or interface and access it only from those that use it, > regardless of what file or "module" (namespace?) they are in; the logic > can be encapsulated to where it is used, not where it is defined. > > interface Shipment { > protected class Items {} > public readonly class Destination {} > function deliver(self:>Destination $destination); > } > > class InternationalShipment implements Shipment { > private function handle(Shipment:>Items $items) {} > > public function deliver(Shipment:>Destination $destination) {} > } In this case, I am not seeing what the nesting gets you. Making Destination a normal class doesn't hurt anything here, does it? > However, you can use private nested/inner classes to encapsulate the > logic to where it is defined instead, like file-private would give you. > > The goal here isn't to only to reduce "namespace pollution" but also to > encapsulate related logic integrally connected to the outer class's > behavior. Since you've referenced Kotlin a number of times, I assume > you are familiar with the concept of nested classes there? This is > extremely similar. My short foray into Kotlin did not include nested classes, so I cannot speak to them other than knowing they exist. --Larry Garfield