Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126331 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 B1B171A00BC for ; Fri, 7 Feb 2025 14:24:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1738938086; bh=rcE7K7/wZbWLFqeOwxCynDHXeILh4035WZZ948q49co=; h=Date:From:To:Subject:From; b=Ox7al+vPwLVt12IcSMSZcksZD+4Gmc1rtrioIWJi4lHW95xkpjkbbSut07FONjCbA nEj01qAvy3jzYKhyOrWbXacfDNMz50f8AaBxw22uiJ8DQFrJbxW7m4TT7+q7hjsdfd 5WLzqVQ0ERssZYJKYPLjXwkSsrofB4hRKWZsbmj44Andn+ZYWX8Zd7VSeHCnm2oNZC cVbHARNgt01voI/e7b2AtuRTT7Yc5/jd7N2VYts0B/ijDVq4/YFVbABOk5atJ0OoNT dNkSLYix0+x9btBV6kYyIVlxfWBF62nqMU5ZA1B/rcXqtJ7M2wbitib0MZlL0/LhRH NUsrm6tXGYvQA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1207E180034 for ; Fri, 7 Feb 2025 14:21:25 +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=-0.1 required=5.0 tests=BAYES_50,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-b4-smtp.messagingengine.com (fhigh-b4-smtp.messagingengine.com [202.12.124.155]) (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, 7 Feb 2025 14:21:24 +0000 (UTC) Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfhigh.stl.internal (Postfix) with ESMTP id 0DAC725401BA for ; Fri, 7 Feb 2025 09:24:09 -0500 (EST) Received: from phl-imap-09 ([10.202.2.99]) by phl-compute-01.internal (MEProxy); Fri, 07 Feb 2025 09:24:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc:content-type:content-type:date:date:from:from:in-reply-to :message-id:mime-version:reply-to:subject:subject:to:to; s=fm1; t=1738938248; x=1739024648; bh=ThgtbM2MGZdG8+x61IG4+UhcVhs8LnE/ lpEuC+Mov6E=; b=f+w+Mzbt/NPROKyWFMjIPwl+bD1+ej2mYgn+eZFH7MkwZIKN 7ueJOcRTVliD/w1Yrc4i2XhA4uO3z8FnXQsSqJencjiZ3RSs826TENON85muIi1Z +tntIQ4Q2VUWyq+tPZan2l3vb2twFOS70IGsDLfjSX46egyO+2cR/WViCXjFTXxs XISQieQfGf2Dqt3x0eKK9/IZtxFvS/HQR8LYNcuA8BObSdDcHPhIycBVVr39XR1k J3KGF2a5AzGsI5QPtGMOXdCiUb5e7m8wBdu0oX3HUH8G6af68/lNFWcwC0dlqqgh bwWuKIlQCmC86S3m3FFf2B9NGTIdesSI0zIR3g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:message-id :mime-version:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1738938248; x= 1739024648; bh=ThgtbM2MGZdG8+x61IG4+UhcVhs8LnE/lpEuC+Mov6E=; b=l Hbab+CBwvT614qtq8N5QwCtPQYlTu5deZ4CGJL1n4bXH1KNCOm8/Hx2ob4w7fhWg KVhSQ0hnDRN77fQZBOIL54eceDuEDmeWwkyijZxXX8vykbMFhf2rTvOwy5mwlVhl IJS+ub8VMa7rRB34b0pDwxigv2hYa2eeq5sDKjEQ1hWPqcE2b5FF/Es5LDv4vVEc DrSO44Jpr7Q15fdtydLPuWS0mzgiaydlnPjsl9rbazfnGKztD3gjixGmL6eIWYNh McFfA03b8UwdeDR01/U4ACW/1l/gef/PBWhnjYGjxsMPtHi5nh7PrNQjNgn6AnLX J2DKISJnP0r/LjLg/mfcQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvleehudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhepofggff fhvffkufgtsegrtderreertdejnecuhfhrohhmpedftfhosgcunfgrnhguvghrshdfuceo rhhosgessghothhtlhgvugdrtghouggvsheqnecuggftrfgrthhtvghrnhepveegkeejfe etudejtdfgudfhtdeiieehhedvgeeiieduffejgfevvdelffejgeffnecuffhomhgrihhn pehphhhprdhnvghtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilh hfrhhomheprhhosgessghothhtlhgvugdrtghouggvshdpnhgspghrtghpthhtohepuddp mhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepihhnthgvrhhnrghlsheslhhishhtsh drphhhphdrnhgvth X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 91027780068; Fri, 7 Feb 2025 09:24:08 -0500 (EST) 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 Date: Fri, 07 Feb 2025 15:23:48 +0100 To: internals@lists.php.net Message-ID: Subject: [PHP-DEV] Short class syntax and inner classes Content-Type: multipart/alternative; boundary=4c208bcbc1a246479cd727fac7853874 From: rob@bottled.codes ("Rob Landers") --4c208bcbc1a246479cd727fac7853874 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hey internals, You may remember my RFC about Records (https://wiki.php.net/rfc/records)= . There was something intentionally left out, and due to life events, I = am quite behind schedule on this one. BUT, what I left out (and the main= reason for the short syntax) is the ability to have locally scoped reco= rds in a class definition. Example using an anonymous record: $x =3D new class { public record Point(int $x, int $y); // from inside the class, there is no special scope public function foo(): Point { return new Point(1, 1); } } $point =3D new $x::Point(1, 2); Anyway, I think I've settled on an implementation that is acceptable, bu= t I wanted your feedback before moving forward. Instead of this being limited to Records -- an entirely new type of type= and syntax -- would we rather have short class declarations (similar to= the rules in the Records RFC) and locally scoped classes? class Outer { // able to be instantiated from anywhere public class Inner(int $y); // a private/protected class can only be instantiated within methods/c= lasses bound to Outer protected readonly class ProtectedInner(int $z); } Instantiation is done by static access: new Outer::Inner(1), which is cu= rrently a syntax error. Public nested classes may be used as type hints = and return types as well as properties in other classes. There are quite a few more things left to investigate before updating th= e RFC (or drafting a new one), but I am at a crossroads and I wanted to = gather people's feedback first. If this is a big "NO" (or if someone els= e has started working on this and I'm just so happening to accidentally = step on their toes, again): I don't want to spend several days/weeks dig= ging into the details for classes. However, it would probably look somet= hing like the above. Note, this doesn't preclude you from using a longer syntax, if that is y= our preference. class Outer { public class Inner { public function __construct(public int $z) {} } } Anyway, I'd love to hear any preferences or thoughts -- strong or otherw= ise. I probably won't reply, but I will read everything and take it into= consideration as I continue down this road. Also, if there is already someone working on this ... please speak up so= I don't get accused of stealing ideas again! =E2=80=94 Rob --4c208bcbc1a246479cd727fac7853874 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
Hey internals,<= br>

You may remember my RFC about Records (https://wiki.php.net/rfc/record= s). There was something intentionally left out, and due to life even= ts, I am quite behind schedule on this one. BUT, what I left out (and th= e main reason for the short syntax) is the ability to have locally scope= d records in a class definition.

Example us= ing an anonymous record:

$x =3D new class {
=
  public record Point(int $x, int $y);
  // from inside the class, there is no special scope
  public function foo(): Point {
  &nbs= p; return new Point(1, 1);
  }
}
<= div>
$point =3D new $x::Point(1, 2);

<= div>Anyway, I think I've settled on an implementation that is acceptable= , but I wanted your feedback before moving forward.

Instead of this being limited to Records -- an entirely new typ= e of type and syntax -- would we rather have short class declarations (s= imilar to the rules in the Records RFC) and locally scoped classes?
<= /div>

class Outer {
  // able= to be instantiated from anywhere
  public class Inne= r(int $y);
  // a private/protected class can on= ly be instantiated within methods/classes bound to Outer
&= nbsp; protected readonly class ProtectedInner(int $z);
}

Instantiation is done by static access: new = Outer::Inner(1), which is currently a syntax error. Public nested classe= s may be used as type hints and return types as well as properties in ot= her classes.

There are quite a few more thi= ngs left to investigate before updating the RFC (or drafting a new one),= but I am at a crossroads and I wanted to gather people's feedback first= . If this is a big "NO" (or if someone else has started working on this = and I'm just so happening to accidentally step on their toes, again): I = don't want to spend several days/weeks digging into the details for clas= ses. However, it would probably look something like the above.
=

Note, this doesn't preclude you from using a lo= nger syntax, if that is your preference.

cl= ass Outer {
  public class Inner {
&nbs= p;   public function __construct(public int $z) {}
=   }
}

Anyway, I'd love t= o hear any preferences or thoughts -- strong or otherwise. I probably wo= n't reply, but I will read everything and take it into consideration as = I continue down this road.

Also, if there i= s already someone working on this ... please speak up so I don't get acc= used of stealing ideas again!

=E2=80=94 Rob
--4c208bcbc1a246479cd727fac7853874--