Newsgroups: php.internals
Path: news.php.net
Xref: news.php.net php.internals:126610
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 32BC71A00BC
	for <internals@lists.php.net>; Thu,  6 Mar 2025 22:20:51 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail;
	t=1741299495; bh=9G44w/6QuRy9iTpftGIA8bCNPp1QTyJOfC9Tjg4aPho=;
	h=References:In-Reply-To:From:Date:Subject:To:From;
	b=HaWpCQaF5YzKFv/xSCwhPdqqO0J+ZgyE4zImqTIvvOgxQKh8bKTDiLYQDv5GPeC86
	 4o63se9E3t6HeWKnfBJk0OIPElCZ4fFFUqOhLJJYG0K0y6Y2qeNEjd7RkZ/MxFghGD
	 UgSWXBVB4C7t6a05DSOhflaOQSqOWpWpKsDBWMvHYL1pkw7u/QFQfQKa5Xoos5pWTo
	 QZvdNMu+YWK46mwiUefi4Ezf4gWA4oFyEa1xfnR8z8MKImU+dhgwo3joILcry9RNUU
	 zOq4165nBKBUztDG1YKonPuYaf+KuFn3mqOhMc6D/HT3E6Bn2ArpZeuffEzI2KdGl+
	 f2eMM+ORvS7iQ==
Received: from php-smtp4.php.net (localhost [127.0.0.1])
	by php-smtp4.php.net (Postfix) with ESMTP id B7BA2180080
	for <internals@lists.php.net>; Thu,  6 Mar 2025 22:18:14 +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.0 required=5.0 tests=BAYES_20,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM,
	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: <tovilo.ilija@gmail.com>
Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172])
	(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 <internals@lists.php.net>; Thu,  6 Mar 2025 22:18:14 +0000 (UTC)
Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-7c07b65efeeso113148585a.2
        for <internals@lists.php.net>; Thu, 06 Mar 2025 14:20:49 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20230601; t=1741299649; x=1741904449; darn=lists.php.net;
        h=content-transfer-encoding:to:subject:message-id:date:from
         :in-reply-to:references:mime-version:from:to:cc:subject:date
         :message-id:reply-to;
        bh=3bVQWkZMUgyqZd8C8/s1Np48trRSRkbZftaV6y5TXW4=;
        b=TjyWVCLbLh3iNu4To/Cn4FzdNC3o2mdKLKTlma+oBUh9NKm1qH9NLJfXRvvJ7ggtgG
         mJ/olTklGkGXm6/1pBkQa5mAYIIOiFN1CDt4hh6HwesA9peyIw2nYng9DNlUkK0oNhkd
         5idkUNiR9nc7s1lJkkixUSoN0UqcqmoKKd2GIWr/WQIS1NciFGqb+SQIPQlTjwgAA5H/
         SOUg6gZxlUE250QV+S7C8m16SAc50FPKgfdP8RQZQyGo1luO/PV59LzgEqPkvJJ5pHap
         zY4PjoO5LJIjZrUH8CweWo7S4CSzgM3m0gzby2vuLw9gMkiVjWkcaRrH/+J12I5rknvT
         zyng==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1741299649; x=1741904449;
        h=content-transfer-encoding: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=3bVQWkZMUgyqZd8C8/s1Np48trRSRkbZftaV6y5TXW4=;
        b=CtGlVekiBnMg5Oha6DH/wfqmIPJr0W9f+R4Uw7OKJRibcgi0DHqYt3RVA/OaDrdORb
         pNnEy9ZgnNRsRNwpoXsE4SDRRUBgYr4aT9kcmmoLMJtdZccKXxg6OD8BMxIp0XxV+MPJ
         wBvHG8abySkWmd89ikRtAHeN1vIHUDyB3n/MTtb8GAhqGSUeiq8E84MoV6zIrx6p7uuJ
         rITJEu4RQ2zwzXPtYzifKT/aW3+X/2THUZF51O4NwFV9lkBRokuNwQy8fGtHqPueS2Tu
         OONmZKIURvmpkhOeKMBEHUwqqvfiJdw2N6Dr4iBEEJfZHqcUK8Xd5n90RSNS0YUge6q7
         ROkQ==
X-Gm-Message-State: AOJu0YyJC9DbF2dl7VulumlnzIRu/LpeFICTy/TxPS482ddzFyOApDzY
	b4d9jhWZA2dZTUBz8xzaC+UklYS0GRpHc+BXEZZ+G34h50893r0U9+C0UB+kj8Fsxm/z6DXVQta
	fl3T2kLGNXKhlzuTrTUArSKgKZqR3fxJwMxM=
X-Gm-Gg: ASbGncuMkXiS5bcgQudYv+6tmHYazztiQLtu+pYC5TmC8ue7yH0GDl8CSAvmlybJyHV
	YV3ROdKXJv0Tn7id4K/h0ZFLE7CayeMMMgscdsfVb1lCL18oc7kxdsyk6QndnhWOWTGs/ks6JSy
	AwauR58RVQeBF4moz5fqmuybWrbjJoAdFE5TWwUW5IAXRGzXlref5w8aGfXrMn
X-Google-Smtp-Source: AGHT+IHSZNBl+CalXU8y6CtwW4GFWmEtSRYVvtuh1QBVfRerHskfnsmjjp0Qwidx2TsDAeyle5x3z/EFxstbi7PfdLk=
X-Received: by 2002:a05:620a:27c8:b0:7c3:c59b:6d1a with SMTP id
 af79cd13be357-7c4e60f0a3bmr123350685a.20.1741299648861; Thu, 06 Mar 2025
 14:20:48 -0800 (PST)
Precedence: bulk
list-help: <mailto:internals+help@lists.php.net
list-unsubscribe: <mailto:internals+unsubscribe@lists.php.net>
list-post: <mailto:internals@lists.php.net>
List-Id: internals.lists.php.net
x-ms-reactions: disallow
MIME-Version: 1.0
References: <aae32397-0567-417f-adbe-6b663d5c49ae@app.fastmail.com>
In-Reply-To: <aae32397-0567-417f-adbe-6b663d5c49ae@app.fastmail.com>
Date: Thu, 6 Mar 2025 23:20:37 +0100
X-Gm-Features: AQ5f1JqdRx3BVs_O6VTUOWc-990I77H_Up0vckLh_F9XQKl4MBvPo5n_kk4zM-M
Message-ID: <CAPyj-LAz=3yX7mCYOijw2irrubgs2b3Piqy42_jpkek5ctKkWA@mail.gmail.com>
Subject: Re: [PHP-DEV] RFC: short and inner classes
To: PHP internals <internals@lists.php.net>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
From: tovilo.ilija@gmail.com (Ilija Tovilo)

Hi Rob

On Thu, Mar 6, 2025 at 12:14=E2=80=AFAM Rob Landers <rob@bottled.codes> wro=
te:
>
> I'd like to introduce my RFC for discussion: https://wiki.php.net/rfc/sho=
rt-and-inner-classes

Thank you for your proposal.

I'm very much against the idea of introducing yet another slightly
shorter form to declare a class. In your examples (they have been
removed in the meantime), it's unclear how the syntax interacts with
inherited constructors, trait-used constructors, whether repetition of
readonly parent properties leads to a "Cannot modify readonly
property" error, etc.

The concept of visibility for classes does seem useful to me. Some
questions that crossed my mind when reading the proposal:

> Inner classes may only be nested one level deep, may not be a parent clas=
s, and may not be declared abstract

These restrictions seem somewhat arbitrary. For example, you may want
a private class to extend another private class, creating some local
class hierarchy. I think there's value in relaxing this restriction,
if technically possible.

> PHP Fatal error:  Private inner class Box::Point cannot be used in the gl=
obal scope

How is this implemented? I presume using a public nested class as type
hints should be allowed, but these classes may not be loaded when the
function is declared. We implement delayed variance checks for
methods, which do trigger the autoloader, but functions do not (since
they cannot violate variance rules).

> Visibility Rules: Private and protected inner classes are only instantiab=
le within their outer class (or subclasses for protected) and cannot be use=
d as type declarations outside their outer class. This encapsulation ensure=
s that the inner class=E2=80=99s implementation details remain within their=
 intended scope.

This introduces a weird case where methods with parameter or return
types referring to private classes may not be redeclared in their
subclasses, given that the type cannot be specified, even if the
methods themselves are not private or final. You do mention something
very similar in your e-mail with the __constructor case, but I really
fail to see how this provides any benefit.

I would also like to echo what has been said about the :: operator,
which feels out of place. I understand that \ comes with additional
autoloading challenges, namely requiring a fallback autoloading
strategy that currently does not conform to PSR-4.

Disclaimer: I have not looked at the implementation at all yet.

Ilija