Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126861 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 B7EF61A00BC for ; Thu, 20 Mar 2025 14:51:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1742482109; bh=nQ3wm388ne9YllgHx2UBFEM9jFVCQkGh4OKZ1iHQVIY=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From; b=CYr0kJb3lYWE7JOTfRWazqT31LPtymYSFHy4H19E24tqT9NzlLFJPvuFn+v0UYWcg 6JnxSewda9pOftPE1uz6fRbqiPcFgFOCOZb7UVB/XZHFmxhGH1Fflk8tmCyoDBWaEy nTo9o6NGy4C/GzwHL2TR9q6N4pq6W3wU2aCpgaG/uUowBMwTPFatY2ZG0PZId9L7GH QSuUbiXxhFuffhJSq6PlPbI0884R1F4RwPwjZQsahtYwp+uFsPgvdlTLFwF70hYvfu efNY28iYNVW5SO7s8tR27nfQdG/9m5ga72hYPqIXgPHqaLCze3ge5wApZYo52qwUsB jwRsdpIZyVSYA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C21AE180566 for ; Thu, 20 Mar 2025 14:48:28 +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,HTML_MESSAGE, 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 fhigh-b8-smtp.messagingengine.com (fhigh-b8-smtp.messagingengine.com [202.12.124.159]) (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, 20 Mar 2025 14:48:28 +0000 (UTC) Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfhigh.stl.internal (Postfix) with ESMTP id 0293825401EE; Thu, 20 Mar 2025 10:50:58 -0400 (EDT) Received: from phl-imap-09 ([10.202.2.99]) by phl-compute-11.internal (MEProxy); Thu, 20 Mar 2025 10:50:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc:cc: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=1742482258; x= 1742568658; bh=i+ghBif4VZut/hEBtwQ5Hra6RjajMWu0/xrPXMiinpE=; b=X Gkqd89S3616ean6ty8Ap58eIIwtxPjTPYdI0GEikDsdFCOQJSXTOnYAdp91E8h+b ccYP2gtadllJrKYkZLvVSWCFCNcx7+BVJAj8Dv3wLgMxzbH7GyCRfmjl0kzDCvbj mkRbUUK2d1g9QuHViZnbGxE6Z5GScFAs24oHDGnthzYwND7tfJV77ogDd7lo7UEY qyUGHsYmUcOCMfe6qQ5ILGKf9yzxGOR8kpy8AaqLXx633g7UNcGveytc6vJazY9h MQpXm9oFGdqCcNfYqPE6tq63YX+qXyqa0fxwcjgJKfOVZbMo7o8KnPXXKCaQ51HG PBhpTzgwlvGF7AHoFe62Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc: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= 1742482258; x=1742568658; bh=i+ghBif4VZut/hEBtwQ5Hra6RjajMWu0/xr PXMiinpE=; b=8gJ/GGu3KJIJPVcpYEO1R94LHSnx50DGYKf/hWf+aqsGh5QGHs0 V/cVh3vPqx26PVRh1qdA/SA/VwTwXJKVCC1dwAxCvAXXDHXgkS1o9sTlIahd/wY3 ZOgyibt2QhYOmkcW8g2N0AUx/G8eI/KI94GPZvB34wXuU0DMw0K+/NSfzP/LDbEq ZD7YK/YglZNTMhg1bB5erFbbiqsx7tGthucXwHRthwbwU9BwONNx5LZSTYpDf/UE G3R0wVuXcDi6JxGiTgqOVdD1vUZZpef8uCvHs0Tc5qkiIB63VVZkA4em75UttxiX rppZI994YwOzXnWtlWVBaBTfJ1Ydre17PoA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddugeekgeelucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhepofggfffhvfevkfgjfhfutgesrgdtreerredt jeenucfhrhhomhepfdftohgsucfnrghnuggvrhhsfdcuoehrohgssegsohhtthhlvggurd gtohguvghsqeenucggtffrrghtthgvrhhnpeeiueethedvvdefjefhgfeiheelheehtdfh feekjefflefgvedvkeduteejjedttdenucevlhhushhtvghrufhiiigvpedtnecurfgrrh grmhepmhgrihhlfhhrohhmpehrohgssegsohhtthhlvggurdgtohguvghspdhnsggprhgt phhtthhopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopegsohgsfigvihelse hhohhtmhgrihhlrdgtohhmpdhrtghpthhtohepihhnthgvrhhnrghlsheslhhishhtshdr phhhphdrnhgvth X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 8B7C6780068; Thu, 20 Mar 2025 10:50:58 -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: Tb82dc1343eb6237f Date: Thu, 20 Mar 2025 15:50:38 +0100 To: "Bob Weinand" Cc: internals@lists.php.net Message-ID: <8a16b81c-7dab-4523-a352-76ba0cb4e771@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> Subject: Re: [PHP-DEV] RFC: short and inner classes Content-Type: multipart/alternative; boundary=ed1cec6c477d4c7cb0dbc849acecc010 From: rob@bottled.codes ("Rob Landers") --ed1cec6c477d4c7cb0dbc849acecc010 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Wed, Mar 19, 2025, at 21:09, Bob Weinand wrote: >=20 >=20 > On 19.3.2025 16:04:06, Rob Landers wrote: >> On Tue, Mar 18, 2025, at 03:37, Bob Weinand wrote: >>> Okay, I see the point with LSP. I'm not sure whether we need to pres= erve LSP for that specific scenario, but neither can I say that we shoul= d ignore it. >>>=20 >>> (Effectively implementing LSP would mean that there's an implicit in= terface matching all public method signatures of the parent class, for c= hild classes - which is doable, but possibly too much for the initial RF= C.) >>>=20 >>> I would however ask, should we not implement LSP compatible inner cl= asses, to enforce that no child class may name a class the same than any= non-private inner class declared by any of its parents, until we resolv= e this question (in possibly a future version of PHP). >>> I do not think we should bar ourselves from allowing this in the fut= ure. >>=20 >> I'm not sure I understand what you are asking. But I think you are sa= ying the following should be illegal? >>=20 >> class ParentOuter { >> class ParentInner {} >> } >>=20 >> class ChildOuter extends ParentOuter { >> class ParentInner {} // not allowed >> } > Precisely. >=20 >>> And not pretending starts with using a different symbol than a backs= lash. >>=20 >> I have been thinking about this for a couple of days now... When thin= king through the ramifications of my decision to use :> over ::, this wi= ll also affect generics, most likely -- whenever that happens. This is b= ecause if this RFC passes, generics will want to be consistent with what= ever exists currently. >>=20 >> If we were to use :>, then generics would probably look something lik= e this to be consistent: >>=20 >> class Box { >> public function add(self:>T $item) {} >> } >>=20 >> The same thing would also probably apply to :: >>=20 >> class Box { >> public function add(self::T $item) {} >> } >>=20 >> With `\`, it nearly follows exactly what you would expect-ish: >>=20 >> use \Box\T as T; >>=20 >> class Box { >> public function add(T $item) {} >>=20 >> // or without use >> public function add(Box\T $item) {} >> } >>=20 >> With `\`, we can also just automatically check the current class as p= art of namespace resolution when compiling: >>=20 >> class Box { >> public function add(T $item) {} >> } >>=20 >> This would also make it easier to user inner classes: >>=20 >> class Outer { >> public class Inner {} >> public function foo(Inner $bar) {} >> } >>=20 >> The other syntax options do not allow this; at least, I don't think s= o. I'm very heavily leaning towards `\` as the separator. >>=20 >> =E2=80=94 Rob > I'm failing to understand why you'd think this would be related at all? >=20 > If we get generics, >=20 > class Box { > public function add(T $item) {} > } >=20 > would just work, without any use or such. There will not be a symbol B= ox::T or Box\T, just all mentions of T within the Box class will be take= n as "this is the generic placeholder" and the compiler takes care. > It's not like that T will be directly accessible from outside of the c= lass or actually a proper type, unlike inner classes. >=20 > A generic is not an inner class nor will it look like it. Also, there'= s no accessing of a parents generic - you write class Child extends P= arentClass - or something along these lines, getting the T available = for your class. >=20 > Bob Yes, that is the question right? It might not affect anything there, but= there would probably be an argument to keep it consistent with inner cl= asses. In PHP, a class is a type; thus an inner class is an inner type, = and generic types are also an inner type that only exist in the scope of= their enclosing class, just like private inner classes. If my logic is incorrect, let me know. =E2=80=94 Rob --ed1cec6c477d4c7cb0dbc849acecc010 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable


On Wed, Mar 19, 2025, at 21:09, Bob Weinand wrote:
=


On 19.3.2025 16:04:06, Rob Landers=0A wro= te:
On Tue, Mar 18, 2025, at 03:37, B= ob Weinand wrote:

Okay, I see the point with LSP. I'm not sure whether we need=0A = to preserve LSP for that specific scenario, but neither can I=0A = say that we should ignore it.

(Effectively implementi= ng LSP would mean that there's an=0A implicit interface matchin= g all public method signatures of=0A the parent class, for chil= d classes - which is doable, but=0A possibly too much for the i= nitial RFC.)

I would however ask, should we not implement LS= P compatible=0A inner classes, to enforce that no child class m= ay name a class=0A the same than any non-private inner class de= clared by any of=0A its parents, until we resolve this question= (in possibly a=0A future version of PHP).
I do n= ot think we should bar ourselves from allowing this=0A in the f= uture.

I'm not sure I understa= nd what you are asking. But I think=0A you are saying the followi= ng should be illegal?

class ParentOuter {
  class ParentInner {}
}
<= br>
class ChildOuter extends ParentOuter {
 = ; class ParentInner {} // not allowed
}

Precisely.

And not pretending starts with using a diff= erent symbol=0A than a backslash.
I have been thinking about this for a couple of days now...= =0A When thinking through the ramifications of my decision to use= =0A :> over ::, this will also affect generics, most likely --= =0A whenever that happens. This is because if this RFC passes,=0A= generics will want to be consistent with whatever exists=0A = currently.

If we were to use :>, then= generics would probably look=0A something like this to be consis= tent:

class Box<T> {
&n= bsp; public function add(self:>T $item) {}
}
<= div>
The same thing would also probably apply to ::

class Box<T> {
  public = function add(self::T $item) {}
}

<= div>With `\`, it nearly follows exactly what you would=0A expect-= ish:

use \Box\T as T;

class Box<T> {
  public function add(T = $item) {}

// or without use
&= nbsp; public function add(Box\T $item) {}
}
=
With `\`, we can also just automatically check the current= =0A class as part of namespace resolution when compiling:

class Box<T> {
  public f= unction add(T $item) {}
}

Thi= s would also make it easier to user inner classes:

class Outer {
  public class Inner {}
  public function foo(Inner $bar) {}
}

The other syntax options do not allow this; at lea= st, I don't=0A think so. I'm very heavily leaning towards `\` as = the separator.

=E2=80= =94 Rob

I'm failing to understand why you'd thi= nk this would be related=0A at all?

If we get generics,

class Box<T> {
  public function add= (T $item) {}
}

would just wor= k, without any use or such. There will not be a=0A symbol Box::T or= Box\T, just all mentions of T within the Box=0A class will be take= n as "this is the generic placeholder" and the=0A compiler takes ca= re.
It's not like that T will be directly accessible from = outside=0A of the class or actually a proper type, unlike inner cla= sses.

A generic is not an inner class nor w= ill it look like it. Also,=0A there's no accessing of a parents gen= eric - you write class=0A Child<T> extends ParentClass<T&g= t; - or something along=0A these lines, getting the T available for= your class.

Bob

Yes, that is the question right? It might not affect any= thing there, but there would probably be an argument to keep it consiste= nt with inner classes. In PHP, a class is a type; thus an inner class is= an inner type, and generic types are also an inner type that only exist= in the scope of their enclosing class, just like private inner classes.=

If my logic is incorrect, let me know.

=E2=80=94 Rob
= --ed1cec6c477d4c7cb0dbc849acecc010--