Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126771 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 BBA661A00BC for ; Fri, 14 Mar 2025 23:21:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1741994350; bh=G2vHo5a3K6NIJZXR2bRg4IUXsQ5ZAn8pH/InKW3fK9w=; h=Date:Subject:To:References:From:In-Reply-To:From; b=WZ+n81Ka+8qmfokFlZ0bGUGQC/+McVLKWyJB2qNFFLPRGlFyhzwt2HXrG0iLI7wdQ 3NDemSzQ2bZLRA3mZTIJkhKqJk5vKKMmVSDlO1tbGFWyPg21i7pRQmNvMvWh+CrevO KFgMdlGgKjcB+JVhAJY/XLFIroonRNjw+7jJuIiIBcko4HBFs6P4lEXP3GC6ml00th yWLOBuUL29zTNIqE5mIWbYEjjk7f6sXCP5ZC48m+hWhLZ0S31c3XZNIXXW1C4MFXnc PVI0kuCnebXGthF+tTSKOfajP1XFcDp3794K5FZjpVWfIJZ9tQsas8luwSCLw69Y9f fqv8n8v/le9oQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C738818007D for ; Fri, 14 Mar 2025 23:19:04 +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.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DMARC_MISSING,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fout-a5-smtp.messagingengine.com (fout-a5-smtp.messagingengine.com [103.168.172.148]) (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 ; Fri, 14 Mar 2025 23:19:04 +0000 (UTC) Received: from phl-compute-07.internal (phl-compute-07.phl.internal [10.202.2.47]) by mailfout.phl.internal (Postfix) with ESMTP id 59B281380A62 for ; Fri, 14 Mar 2025 19:21:36 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Fri, 14 Mar 2025 19:21:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rwec.co.uk; 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=fm1; t=1741994496; x=1742080896; bh=e+wzl3uRXqUvFZIAGJ95O1x3v2xKqMC3qn2CGR2dow8=; b= PZ0Zsk9DiGjA597xZtBqHgpKPxiNF0g+cv4Q/ZMJbqEPu2VYOFaxMU9XMozVx+hN EnQCOtieKokNG0Brd6nCw0EQZYwvS7F8l6qMD018f9Cy/u3XKMNoLe3YLFPlvcp5 mvjMVi7L/WAM4T9fBPTbVC8Pamdxs42HV8rrt4NWUPiDknHrNT8FyV4JYfJzB59g a1N3RISjzB6y+DsBgaDD+iMmiyUNMWX9+A8sf7+evgl208EaCapgfj9LiNn9BrxL mhsJ8ogB4YiXkdKmzi4rHyWzvU/T9kNMqynrIBXrxM7n7Z3UI0M/UXQbxkqzlUpH kDRuFRhuLmf3kk7B+Aw8Zw== 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=fm1; t=1741994496; x=1742080896; bh=e +wzl3uRXqUvFZIAGJ95O1x3v2xKqMC3qn2CGR2dow8=; b=BIKf/4og8N65DsBfq nBxHWY60G/gW0BQuyXHdo4UI3YqfFirNGF84O4RSeQMTwg+2JXAzcA5hPgJaBZom L+CF21GeyKnoVKE4/ctnyK6mU28Si+iistLkWnEwKdYGStEF5BNMlbdzjWCwnpF5 nKYbtEFYJDOmvdJC6UYoINkpuLO6BYS1aLoqj0vpB+Xz7BNoAB8AtipF6rp6060a OiCt6TVa7fdLqDzaiHRflU0x+EPyzr9InhwfhJMYpVbX70XcgmnZG3sDwYCpiRFA tyXzlUEK+PDpJQcEaw5FIgrrg5vqt5IvTj9UKhRFW6WuqUJbh3FTASH5g6qWI6sY OEQBw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddufedvudefucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefkff ggfgfuvfhfhfgjtgfgsehtjeertddtvdejnecuhfhrohhmpedftfhofigrnhcuvfhomhhm ihhnshculgfkoffuohfrngdfuceoihhmshhophdrphhhphesrhifvggtrdgtohdruhhkqe enucggtffrrghtthgvrhhnpeelhfekudeikeduiedufeeitdejvdegjeeuffeljedtudeg veekhefhhfeggffgleenucffohhmrghinhepphhhphdrnhgvthdpmhhitghrohhsohhfth drtghomhdpohhrrggtlhgvrdgtohhmpdhkohhtlhhinhhlrghnghdrohhrghdpshifihhf thdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehimhhsohhprdhphhhpsehrfigvtgdrtghordhukhdpnhgspghrtghpthhtohepuddp mhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepihhnthgvrhhnrghlsheslhhishhtsh drphhhphdrnhgvth X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 14 Mar 2025 19:21:34 -0400 (EDT) Message-ID: <70f34dcf-e4b6-4d92-8417-83ebeb03153c@rwec.co.uk> Date: Fri, 14 Mar 2025 23:21:32 +0000 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] RFC: short and inner classes To: internals@lists.php.net References: Content-Language: en-GB In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") On 05/03/2025 23:11, Rob Landers wrote: > > I'd like to introduce my RFC for discussion: > https://wiki.php.net/rfc/short-and-inner-classes As a user, I find the concept of inner classes quite confusing. However, I was looking at some code earlier and thought an "inner enum" would be useful, to replace various "MODE_FOO" type class constants - but I see those are left to future scope. :( I'm aware they exist in a lot of other languages, though, so I thought I'd look around at how the proposed version compares. It seems there's quite a zoo out there... One common theme I do note is that all four of the pages I found are titled "nested classes" or "nested types"; in some cases, "inner class"/"inner type" has a specific meaning, which I don't think matches the RFC's proposal. C# - https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/nested-types I think this is most similar to what you're proposing. Interestingly, the nested class defaults to being private, i.e. only usable within the parent class. Classes, structs and interfaces can all be nested inside each other. Java - https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html There are two types of nested class (plus some more related concepts which seem less relevant) - "Static nested classes" - static in the sense that they act like a static member of the surrounding class; appear to be *only* about namespacing and visibility of the class, with no special access to the surrounding scope - "Inner classes" - associated not just with a parent class, but a parent *instance*, so have to be created with the syntax "ParentClassName.new InnerClassName" or "this.new InnerClassName"; are not allowed to have static members Kotlin - https://kotlinlang.org/docs/nested-classes.html Just nesting a class gives it no special access, but the keyword "inner" causes it to carry an *instance* of the outer class, which can be explicitly referenced with the syntax "this@OuterClassName". Classes and interfaces can be nested in any combination. Swift - https://docs.swift.org/swift-book/documentation/the-swift-programming-language/nestedtypes Type declarations of various sorts can be nested, and have all the visibility modifiers available to other declarations. "Private access restricts the use of an entity to the enclosing declaration, and to extensions of that declaration that are in the same file" - https://docs.swift.org/swift-book/documentation/the-swift-programming-language/accesscontrol/ The example of a nested enum also demonstrates a nice shorthand syntax, where the ".ace" in "BlackjackCard(rank: .ace, suit: .spades)" is short for BlackjackCard.Rank.ace, inferred from the parameter type. I don't have any specific conclusions, but I think with features like this it's always worth examining other people's ideas, to see if we want to include (or avoid) any of them. -- Rowan Tommins [IMSoP]