Newsgroups: php.internals
Path: news.php.net
Xref: news.php.net php.internals:126810
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 D2D201A00BC
for ; Mon, 17 Mar 2025 18:05:55 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail;
t=1742234603; bh=IG/WQsO97Ah3SkX8qMQrdnpoEz8GNcXA9iNS1p6ZvEU=;
h=Date:Subject:To:Cc:References:From:In-Reply-To:From;
b=CeZ9tIrfI43/xa5ZRmSDi4msIM7aBsoT7uYnYW4KcF7eANjb2SVVIFmV841D2RFRR
YhArA3jnHjiIIN04RI1jFNS0dXcWFrbIsuT4qHrLDTtMpvGBHkLaKG41ogkAtBQMKD
uXx6TvwWHW2D/35GpQxHlB1Jfhyej28RRH4n3Aw5scpFanTqXSfGPHPcad37nP/nzU
ARoQfHyvcpD9jl01zW0qumPK+MFNXugjV18cPbt5hC8Nv6cnRUAfILdZ7hAwbxXAlU
G8VFPhLCj1T6ZTJs67GiN7rxHyzCxvQigtOvBTGAKVR+s7zKmn9NSJ/QXd1wA1Iokd
nVcDxyIR6ithQ==
Received: from php-smtp4.php.net (localhost [127.0.0.1])
by php-smtp4.php.net (Postfix) with ESMTP id 9DF0F180053
for ; Mon, 17 Mar 2025 18:03:22 +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.6 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00,
DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,
FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,HTML_MESSAGE,
RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=no
autolearn_force=no version=4.0.0
X-Spam-Virus: No
X-Envelope-From:
Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2093.outbound.protection.outlook.com [40.92.89.93])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange ECDHE (secp384r1) 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 18:03:22 +0000 (UTC)
ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none;
b=XRKniogQtHxhh8vlQvzom/bzIwPjPpBcZoBt86ENcvFySzkdnUWIHn72RnGi4AQwHND2ojp42vRgoYOoKt1G+DN90lvlpdomStNQkQ68hSOsoUkJIamLE2J1vsqJcEIvCccVolOl7UXvs/2JbDOxxDnb7tpkgX62Ojibawj4uS24714tRURZgWcKPnKb6nklKE+4snTAlJw4jxmPCkAf6S4Fk0Zb+1kojILBRX2aaib3EPKZMexjmdS43ahYjeoawPUrAunmPzuhYJTJFhF7RUKqJgB0QLPaiM1mLjouNlLHZWAnM/xL/+13LTfV807rWvNCKLdpXQ/+BPWD9e64TQ==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com;
s=arcselector10001;
h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1;
bh=q5pUAOLGhsHah5czq5JbQq29F1as4wBeeS9X7s/Z84I=;
b=fuGoU5MV4oabvYqs/n5M4M00OBnTeFXXCid87vgMYYnCO0SgN4RbLn4W0YNtX+BVnTgMK9KSslUy0c/9fLNyvhi1DJ3uXtU0b+4SBWm7okl/fhrf5un8t2tX14+2/yCvOkKTTHaZR0l97xhmngEI90iAE25PVQpvc/mA+nQoh19TQRZjVskktVE8GKCey4E7LdBYgGr8Q17DJjHIcrhUxHzWuzwkYcBklSsnKNhSNS8HAnG43tAJIpn68P88ekvFsZNPCR0qRlOSrBZVEDofG7J6CjTNG9nc7u2nl+PbkYFqzChNAlENHjE+BnsE+FJE5Vt2dD9Ui1xNQg/E0UQQ9w==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none;
dkim=none; arc=none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com;
s=selector1;
h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
bh=q5pUAOLGhsHah5czq5JbQq29F1as4wBeeS9X7s/Z84I=;
b=Indrygv4YAaky1FrZ/6HX6KtMI9J6DX3Hj1lZSOYy1CJ2US89AOknem+33wJTqJTp9jjd5jGzI84laW32Cw0D9+XJyFi7A3X2m9aH0aV3T6Txvtt8fJvuLrQNdavaNwxosW7CS9qxAMQTVJAAXgjSkKYFKFgJucM6EXgqBviOU+jlPRHf1YMXV0zOm0MC/rJwx3+qvrM6sAjun6Dh1nxWLu/ePgGvIVxkJyo5axV09FgPaCJuzjZ8u8awnuJ/wSrzSPV/BNTqGMK/gUZ1c19DPKzPn7p4HdQA0zt7vaJqRpvTAHWbGivS1FqLw60w8f7sBY1txu1kwrBcKUDm/jfxQ==
Received: from AM8P250MB0170.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:321::21)
by AS1P250MB0631.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:48e::16) with
Microsoft SMTP Server (version=TLS1_2,
cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8534.33; Mon, 17 Mar
2025 18:05:50 +0000
Received: from AM8P250MB0170.EURP250.PROD.OUTLOOK.COM
([fe80::651e:bbd2:b18a:80ff]) by AM8P250MB0170.EURP250.PROD.OUTLOOK.COM
([fe80::651e:bbd2:b18a:80ff%3]) with mapi id 15.20.8534.031; Mon, 17 Mar 2025
18:05:50 +0000
Content-Type: multipart/alternative;
boundary="------------WbsUQY29zOp7Z7MLi2uLluuI"
Message-ID:
Date: Mon, 17 Mar 2025 19:05:49 +0100
User-Agent: Mozilla Thunderbird
Subject: Re: [PHP-DEV] RFC: short and inner classes
To: Rob Landers , fennic log
Cc: internals@lists.php.net
References:
<3e4ba7ea-a154-452d-abfc-05ef1322fade@app.fastmail.com>
Content-Language: en-US
In-Reply-To: <3e4ba7ea-a154-452d-abfc-05ef1322fade@app.fastmail.com>
X-ClientProxiedBy: FR4P281CA0151.DEUP281.PROD.OUTLOOK.COM
(2603:10a6:d10:ba::17) To AM8P250MB0170.EURP250.PROD.OUTLOOK.COM
(2603:10a6:20b:321::21)
X-Microsoft-Original-Message-ID:
<59a9415a-bfdb-4a72-a1cb-8e5c4c1cde62@hotmail.com>
Precedence: bulk
list-help:
list-post:
List-Id: internals.lists.php.net
x-ms-reactions: disallow
MIME-Version: 1.0
X-MS-Exchange-MessageSentRepresentingType: 1
X-MS-PublicTrafficType: Email
X-MS-TrafficTypeDiagnostic: AM8P250MB0170:EE_|AS1P250MB0631:EE_
X-MS-Office365-Filtering-Correlation-Id: 7334f4e8-4cfc-4962-5e6f-08dd657e5992
X-Microsoft-Antispam:
BCL:0;ARA:14566002|12121999004|461199028|19110799003|8060799006|5072599009|7092599003|15080799006|19061999003|3412199025|440099028|12091999003;
X-Microsoft-Antispam-Message-Info:
=?utf-8?B?REJ3YWpteDZHanRoamFQcDY0NWVheTR3MzExY3gwczg5V3JhTXZJUWF3aTU2?=
=?utf-8?B?UTMyVFpuZzEvbEpSc05ldW9vbVBuZjBPSGZnWW5lOU9PS2VONUYyRUJ6dmg5?=
=?utf-8?B?WHVhL3JTTnpVTDVpdU15RmJtcVYyMFVnSTFER1pHU1RpcUV3VW9BRkVUWjJ2?=
=?utf-8?B?T3NjMnEwclU1VUs4ek5KVTcrQ0NGQ2E2Y0VMeFFCeWNnQ0JGTnh3dDIrRDRp?=
=?utf-8?B?djh5MW9zV1YrSCs5MVlyaHFlVEsrcnpmMTdFY3phbzJzNllrSFNpdklxejJ5?=
=?utf-8?B?SSs3bkZ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tkbGdnSGg0RXAwZzBQVUoxMytzTG1L?=
=?utf-8?B?ZkVPVVB1di92QWxFU2RJbHpYcEcvTGQvVE9zZVZJdFdHa3N4eEN4QUtNSlcz?=
=?utf-8?B?dlZxclFQb1crVU52L2dhZUNBbjlXMCtHY05LOTBzY21xL3dhRDV5RXVGV2Y3?=
=?utf-8?B?aWs2cGoybm9xQ0VvaFlQWDRMclRCK3hNeWZvQ1dRYWl5MTVBYitzR3JMTUlH?=
=?utf-8?B?NlJiL1lwYi9XdU9waFRFTGJVRFl1T0lvL2NzOC9lT0RXYkVmTG4wSWIzQmxz?=
=?utf-8?B?N244U0FrMWxyMld4QkF3blEvVlovYmh2NEFZUUNLUG1HaW1peXIyVXlPNEd2?=
=?utf-8?B?M01ycmRHdnQvK20wcXR1LzBTaEh1bkNWWUZycm95b1Z1aWlYU21mVEQ4cHNK?=
=?utf-8?B?WkNKdXdUQTdMTGhrcHdId2NsODVDdnN2QmZEZno0ejlJR0hyWUM4Nkh3RzFE?=
=?utf-8?B?Z1ZzdldDQ0VqWlc2azMwQU5YYVozZUFGejY2T09FRlN4bk1kWkdGVUppN0VN?=
=?utf-8?Q?qo7NXbLg7m5XgIAkUM=3D?=
X-OriginatorOrg: sct-15-20-7784-11-msonline-outlook-95b76.templateTenant
X-MS-Exchange-CrossTenant-Network-Message-Id: 7334f4e8-4cfc-4962-5e6f-08dd657e5992
X-MS-Exchange-CrossTenant-AuthSource: AM8P250MB0170.EURP250.PROD.OUTLOOK.COM
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Mar 2025 18:05:50.3860
(UTC)
X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted
X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa
X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg:
00000000-0000-0000-0000-000000000000
X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS1P250MB0631
From: bobwei9@hotmail.com (Bob Weinand)
--------------WbsUQY29zOp7Z7MLi2uLluuI
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Hey Rob,
On 17.3.2025 17:53:26, Rob Landers wrote:
> On Mon, Mar 17, 2025, at 16:30, fennic log wrote:
>> 2. As with any syntax change and new operator there needs to be very
>> careful consideration, do we need a new operation, or could `::` if
>> the parent is static or `->` if the class is initialized?
>
> There's quite a long thread already about this very topic. That being
> said, the inner class has no bearing on whether the outer class is
> instantiated or not. Originally, I used `::` as the separator, but it
> seems there are some good arguments for `\`, so we will see.
I have not grasped any single argument in favour of \, except "other
languages are doing it too", "existing tooling splitting on backslash
would continue to work" and "we could use the existing use statement as is".
The problems are numerous though:
1. Unlike other languages (e.g. C# and java), namespaces and classes may
share a name in PHP. E.g. class "Y" in a namespace "X" and class "X" may
not exist both. In PHP that's allowed. Inner classes compete with
namespaced classes for their fully qualified name.
2. Autoloading will have to become aware of inner classes.
3. Autoloading will have to do a non-cacheable check for existence on
the inner class, before iteratively testing whether any parent has a
respective .php file. Currently autoloading takes a class name,
transforms it to a single canonical path, and includes it. Always
succeeding.
4. Humans, navigating to a path, will not be able to navigate to a file
directly but have to search for it.
5. Tooling splitting on backslash might assume the 1:1 mapping to the
filesystem and break. It's really not a catch all. Some things may be
broken and some not, but all need to be probably revisited anyway.
6. It makes accessing via parent, self or static weird. These keywords
have always been followed by a double colon. (Even if this particular
RFC does not end up adding them) And it will conflict with a namespace
named "parent" for example.
7. At least right now, every backslash identified symbol is trivially
universally public. With \ as an inner class separator, this would no
longer be the case. Maybe that will eventually change, but today this
can be relied upon.
Also, just because other languages are doing a mistake, it does not mean
we have to repeat it. They are generally doing it because their
identifier separator is universal and it's consistent. It does not mean
that it's without its own problems.
Using the double colon is a very minor BC break (accessing a class by a
class constant value?! That's also quite inconsistent that it works at
all, as you can't do that with normal constants, only class constants.).
Using another sigil would also be possible (like :>). But for the
backslash I only see drawbacks.
Also, nothing precludes us from allowing "use Foo\Bar::Inner;".
>> 3. The idea that extending the parent class doesnt no inherit the
>> child classes doesnt make sense to me.
>> As then if you extend a parent class and call a function of that
>> class which could rely on the existence of an inner class, I can see
>> a lot of headaches caused by this exact scenario.
>> As a developer, if I extend a class, I expect the entire dependance
>> of that class to be inherited, otherwise the extending class won't work.
>
> I'm not sure what you mean. When you inherit a class, you do not
> necessarily inherit everything from its superclass. You are free to
> override it however you want. Since we are defining "types" in the
> sense of PHP, we cannot merely inherit a "type", otherwise we would
> cause all kinds of issues with LSP. This is specifically why
> inheritance works the way it does in this RFC and why `static::` is
> forbidden.
I don't understand the problem here.
for each nested class in parent class:
class_alias(substitute parent class with child class in class name,
class name)
Very simple. There's no magic needed, it can be simply class aliases.
This will also make static, self and parent trivially work.
On 15.3.2025 00:37:08, Rob Landers wrote:
> Classes don't actually know their inner classes -- they aren't like
> properties. In essence, an inner class is just a regular class with a
> funny name and access to scopes it wouldn't normally have access to.
> We could probably add `getOuterClass(): string` if that is useful. It
> is possible to keep track of a class's inner classes, but then that
> introduces a paradox chicken/egg type problem during construction,
> which may or may not be a problem.
>
I don't see the chicken-and-egg problem here. You can simply collect all
the inner class names at compilation. You don't even need to actually
store the zend_class_entry - just collect the names and fetch from the
class table at runtime (and ignore missing ones, e.g. if there was an
error during linking).
--------------WbsUQY29zOp7Z7MLi2uLluuI
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit
Hey Rob,
On 17.3.2025 17:53:26, Rob Landers
wrote:
On Mon, Mar 17, 2025, at 16:30, fennic log wrote:
2. As with any syntax change and new operator there
needs to be very careful consideration, do we need a new
operation, or could `::` if the parent is static or
`->` if the class is initialized?
There's quite a long thread already about this very topic.
That being said, the inner class has no bearing on whether the
outer class is instantiated or not. Originally, I used `::` as
the separator, but it seems there are some good arguments for
`\`, so we will see.
I have not grasped any single argument in favour of \, except
"other languages are doing it too", "existing tooling splitting on
backslash would continue to work" and "we could use the existing
use statement as is".
The problems are numerous though:
1. Unlike other languages (e.g. C# and java), namespaces and
classes may share a name in PHP. E.g. class "Y" in a namespace "X"
and class "X" may not exist both. In PHP that's allowed. Inner
classes compete with namespaced classes for their fully qualified
name.
2. Autoloading will have to become aware of inner classes.
3. Autoloading will have to do a non-cacheable check for existence
on the inner class, before iteratively testing whether any parent
has a respective .php file. Currently autoloading takes a class
name, transforms it to a single canonical path, and includes it.
Always succeeding.
4. Humans, navigating to a path, will not be able to navigate to a
file directly but have to search for it.
5. Tooling splitting on backslash might assume the 1:1 mapping to
the filesystem and break. It's really not a catch all. Some things
may be broken and some not, but all need to be probably revisited
anyway.
6. It makes accessing via parent, self or static weird. These
keywords have always been followed by a double colon. (Even if
this particular RFC does not end up adding them) And it will
conflict with a namespace named "parent" for example.
7. At least right now, every backslash identified symbol is
trivially universally public. With \ as an inner class separator,
this would no longer be the case. Maybe that will eventually
change, but today this can be relied upon.
Also, just because other languages are doing a mistake, it does
not mean we have to repeat it. They are generally doing it because
their identifier separator is universal and it's consistent. It
does not mean that it's without its own problems.
Using the double colon is a very minor BC break (accessing a
class by a class constant value?! That's also quite inconsistent
that it works at all, as you can't do that with normal constants,
only class constants.).
Using another sigil would also be possible (like :>). But for
the backslash I only see drawbacks.
Also, nothing precludes us from allowing "use Foo\Bar::Inner;".
3. The idea that extending the parent class doesnt no
inherit the child classes doesnt make sense to me.
As then if you extend a parent class and call a
function of that class which could rely on the existence
of an inner class, I can see a lot of headaches caused by
this exact scenario.
As a developer, if I extend a class, I expect the
entire dependance of that class to be inherited, otherwise
the extending class won't work.
I'm not sure what you mean. When you inherit a class, you do
not necessarily inherit everything from its superclass. You are
free to override it however you want. Since we are defining
"types" in the sense of PHP, we cannot merely inherit a "type",
otherwise we would cause all kinds of issues with LSP. This is
specifically why inheritance works the way it does in this RFC
and why `static::` is forbidden.
I don't understand the problem here.
for each nested class in parent class:
class_alias(substitute parent class with child class in class
name, class name)
Very simple. There's no magic needed, it can be simply class
aliases. This will also make static, self and parent trivially
work.
On 15.3.2025 00:37:08, Rob Landers wrote:
Classes don't actually know their inner classes -- they
aren't like properties. In essence, an inner class is just a
regular class with a funny name and access to scopes it
wouldn't normally have access to. We could probably add
`getOuterClass(): string` if that is useful. It is possible
to keep track of a class's inner classes, but then that
introduces a paradox chicken/egg type problem during
construction, which may or may not be a problem.
I don't see the chicken-and-egg problem here. You can simply
collect all the inner class names at compilation. You don't even
need to actually store the zend_class_entry - just collect the
names and fetch from the class table at runtime (and ignore
missing ones, e.g. if there was an error during linking).
--------------WbsUQY29zOp7Z7MLi2uLluuI--