Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126801 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 354581A00BC for ; Mon, 17 Mar 2025 10:38:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1742207740; bh=7Lp7fSn38Z4UQnHAq5DqCtC0UGV6iPUvVAzgmrBiSsQ=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=XdjNpmKdXHCGrLVco5O1VDT9hkbKv0h3IaIMD8LiK/EIFWqciEdJsaJswzVL9Z1+A J/DZ76FOt04KnsfYXaGot/2wbkM1jT6jqcJaLKzHNfpB3XRLM6SPBZYtjsa6M/PqrS 60zKfb/2Xzc2UAx4Ops0tcYZOiMMXI0eYIuhOGlgAnB/CFYFPvAUpfrpABl/++a7HJ saKJUvcrDXKBtaDT6l66Ffa9luDZJryTAmNvAKFRoTDxMOzXdccZbQ8HwNLEHVM1k9 VDYmNnzDZJUrWLbO5n92nW0b5pyyWQyPqnNVQce60JrMu7f032mSy1z9C7kDxapiOm hkJyP8+K67g3w== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D8B71180087 for ; Mon, 17 Mar 2025 10:35:38 +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=-3.9 required=5.0 tests=BAYES_00,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.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-yw1-f180.google.com (mail-yw1-f180.google.com [209.85.128.180]) (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, 17 Mar 2025 10:35:38 +0000 (UTC) Received: by mail-yw1-f180.google.com with SMTP id 00721157ae682-6ff27ad48beso35497997b3.0 for ; Mon, 17 Mar 2025 03:38:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742207890; x=1742812690; 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=7Lp7fSn38Z4UQnHAq5DqCtC0UGV6iPUvVAzgmrBiSsQ=; b=KpXpD1gDWSe1diPzMGIeB9TSudW8yUTfKcV4lgWDgA45JikREOXEQMLvX6NxD/wJL1 BCMlGOXvZkEPi3Sy+/RA45osM3MeacUo9xCZObX4LhoDYxlRWM8jQw4seZJPJ7zqwQMi yzOeKaD4Tc69bQccs5Ta1yZJ9jPJT3BckpPubMyHVM7crNNGuxC7X8kZrkZ2HM7liZHs gCc/PLw9rdBHNIdLX8sH9/KSXKbcONu7498BzMcA9AuKM7g0WF+JA6hB4JuG1sJlGPTN WX9jnXAH5wKdwvkY1e9F7KE2ObU5g6NBY6wNGoVqQPXoGmDhmrEF1aEX7Zab6Hsx52tH Fvdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742207890; x=1742812690; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=7Lp7fSn38Z4UQnHAq5DqCtC0UGV6iPUvVAzgmrBiSsQ=; b=oU5oxGoRlBAdpocrZRu62XfMUObIrRvkzpXjh6XKEbJQquRO+h4xm0yUcJtgydH8Ub Ean+S7m9c1uW6PTsS5KMetDsV9Hn1efNemdkGJCSfkIwUbuIKayJ0ulN+h7a3ivcg+H2 H6IQh7xi7CJrViYk+3/CkpqVP4BXE1phDnN+J+q6q/T/gxcMpPl8wRHq1InuGJ7DRC4N 6MLo14YEqQ/olhf66DhmSVdZTITbFG9AtcKIikOFF+urYcXkJyTSsx0cNnDXAXYqbtiY WJb5o1REd9IAjs/ViAfkpcVf7+MXKkJVy8jyZg1GxW3h5p5MCh5EvnNjQa5wcWYwrsS9 xyIQ== X-Gm-Message-State: AOJu0Yzc1KyTDKg20/YHlnA/b/FxsFEAGdwxBrvQQJFuu/pTBkZFfBZz ZPfRH/NKvLf3+6fuT/6DFsJolFdYZoneIyBXt1oLpKIiWdfF7jFhqjBNYCfcAExsexFvoLFW5ey Bx2QsN2fiDdFrkaLhTzb8eYiY6lnxtYlvl68= X-Gm-Gg: ASbGncu8xNqJDDzSOyIcDwjQJrcNL+whKiXqsj8ZSTib4y9ugEkzAsXK1rw39SVNF4/ ngnJfLnbHE5xstQn9Qfgn9E2F83EuAlvnR/ZQ65+e8dS3y4nEBejQ582pYT39X4iJUHKETXtiDB YNCxz2XVaja9nx5xd0h6hQoZE9s7O3YSlSvjEAbw== X-Google-Smtp-Source: AGHT+IGB8+LxMRnAFRsrJyYYiULzGdCN1yleasHDBcL9D9wl64VDFEMKo80oGRPNAvRMhH3+cvCgg45xsizNLuIYfl0= X-Received: by 2002:a05:690c:6e0a:b0:6fe:aa66:5d41 with SMTP id 00721157ae682-6ff460fa00bmr153098797b3.31.1742207889712; Mon, 17 Mar 2025 03:38:09 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <4abd7008-ae33-46fe-8bbd-7c99f7c48158@app.fastmail.com> <0F1E4400-5E26-4E39-88B9-ABD7ABBAEBC4@rwec.co.uk> <8bbb484b-96a3-4a3e-881e-2c47d7f433b9@app.fastmail.com> <7C4630DC-3478-4FDD-88C6-D2B27595F02A@rwec.co.uk> In-Reply-To: <7C4630DC-3478-4FDD-88C6-D2B27595F02A@rwec.co.uk> Date: Mon, 17 Mar 2025 12:37:52 +0200 X-Gm-Features: AQ5f1JpL_gmSIlQKyVxA0P05xyGdH2MPI6pr51NkUZ-DECZmjKUH8_S0gF1eYsA Message-ID: Subject: Re: [PHP-DEV] RFC: short and inner classes To: "Rowan Tommins [IMSoP]" , Rob Landers Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="00000000000064306a06308762eb" From: drealecs@gmail.com (=?UTF-8?Q?Alexandru_P=C4=83tr=C4=83nescu?=) --00000000000064306a06308762eb Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Ma0r 17, 2025 at 9:56=E2=80=AFAM Rowan Tommins [IMSoP] wrote: > > > On 17 March 2025 07:11:23 GMT, Rob Landers wrote: > > > > Which one it resolves to would depend on how you implement autoloading > > > That's just the same as having the same class defined in two files on dis= k > - PHP doesn't know which will be used until an autoloader runs. > > From what I understand of the proposal, the calling code won't know > anything different based on it being "nested" or "namespaced", it will ju= st > see a class with a long name with some punctuation in. > > The problem for me is not autoloading, but that you can't have the two classes defined at the same time, while using some other punctuation it would allow it. I believe that there are other operators that we can use, to allow this. > I rather think the other way round: in the short term, a new separator > would save users a bit of pain with autoloading, but in the long run it > will look like a weird anomaly that no other language needs. > > There was much discussion about various ways to solve the problem stated in the RFC, but I think we need to look at it as a broader picture again. I'll share what I've been thinking about in the past week and didn't yet had time to reply here. Right now, PHP only has public classes. For better encapsulation and cohesion, we want to define some new ways to define classes with some limited restrictions or improved access. Taking examples from other languages, we can have two ways to do this: - namespace private classes, or file-private classes - this controls the visibility of the class at the namespace or file level. They=E2=80=99re ess= entially about managing the scope of classes without changing their fundamental behavior. - nested (inner) classes - this allows a class defined inside another to access private members of its enclosing class, increasing cohesion. And we can have further here just public visibility, or protected/private visibility, for better encapsulation. Given this, I think we could even implement all of these in separate RFCs: - public nested classes - file-private classes - namespace private classes - protected/private nested classes - other-grouping-level-that-will-exist-in-the-future private classes Of all of this, the first, public nested classes are the most simple and would drive cohesion. And maybe we can have only that for now. The other features would be mostly important for encapsulation, with limiting the class visibility. We just need to agree on a separator/operator, and IMHO, it should be clear and distinct from namespace separator, as nested classes are a separate concept. Maybe having a vote on the operator would be enough. (As a note, and this might have been discussed already, but I would prefer to use the term nested class instead of inner class, as in java the inner classes means non-static classes, and I don't think we should go that way.) --=20 Alex --00000000000064306a06308762eb Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

On Mon, Ma0r 17, 20= 25 at 9:56=E2=80=AFAM Rowan Tommins [IMSoP] <imsop.php@rwec.co.uk> wrote:


On 17 March 2025 07:11:23 GMT, Rob Landers <rob@bottled.codes> wrote:=


> Which one it resolves to would depend on how you implement autoloading=


That's just the same as having the same class defined in two files on d= isk - PHP doesn't know which will be used until an autoloader runs.

From what I understand of the proposal, the calling code won't know any= thing different based on it being "nested" or "namespaced&qu= ot;, it will just see a class with a long name with some punctuation in.

The problem for me is not autoloading= , but that you can't have the two classes defined at the same time, whi= le using some other punctuation it would allow it.
I believe that= there are other operators that we can use, to allow this.


I rather think the other way round: in the short term, a new separator woul= d save users a bit of pain with autoloading, but in the long run it will lo= ok like a weird anomaly that no other language needs.


There was much discussion about various wa= ys to solve the=C2=A0problem stated in the RFC, but I think we need to look= at it as a broader picture again.
I'll share what I've b= een thinking about in the past week and didn't yet had time to reply he= re.

Right now, PHP only has public classes.
<= div>For better encapsulation and cohesion, we want to define some new ways = to define classes with some limited restrictions or improved access.
<= div>Taking examples from other languages, we can have two ways to do this:<= /div>
- namespace private classes, or file-private classes - this contr= ols the visibility of the class at the namespace or file level.=C2=A0They= =E2=80=99re essentially about managing the scope of classes without changin= g their fundamental behavior.
- nested (inner) classes - this all= ows a class defined inside another to access private members of its enclosi= ng class,=C2=A0increasing cohesion. And we can have further here just publi= c visibility, or protected/private visibility, for better encapsulation.

Given this, I think we could even implement all of t= hese in separate RFCs:
- public nested classes
- file-p= rivate classes
- namespace private classes
- protected/= private nested classes
- other-grouping-level-that-will-exist-in-= the-future private classes

Of all of this, the fir= st, public nested classes are the most simple and would drive cohesion. And= maybe we can have only that for now.
The other features would be= mostly important for encapsulation, with limiting the class visibility.

We just need to agree on a separator/operator, and I= MHO, it should be clear and distinct from namespace separator, as nested cl= asses are a separate concept.
Maybe having a vote on the operator= would be enough.

(As a note, and this might have = been discussed already, but I would prefer to use the term nested class ins= tead of inner class, as in java the inner classes means non-static classes,= and I don't think we should go that way.)

--= =C2=A0
Alex

--00000000000064306a06308762eb--