Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126740 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 F0DE91A00BC for ; Thu, 13 Mar 2025 20:41:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1741898355; bh=zvbZs5ZSRBDtVAE3bBjtIzH4cs4/H2Zks/0P0dlzvgY=; h=References:In-Reply-To:From:Date:Subject:To:From; b=PP0/aD4n8LP+1dN+Vft44e2iIatgzm9pDlNXyZptqL17ugpgEXvGmuoXKiYEYNLdy keHBrqpf5pjil1FrbgJjHUHqGFLPu+TelOITC8wri7IMSPqFhk/ZwSUoKXywcRPtV8 2ZouhkbU8AubE97q1BaN/LWyogJCHy1r2DpbWdwZouopdQh3KHLZGoeUbCpzdjMe3Q e7dTHcl26cSPrwecBHnFfxwNjzzfZiCZQzM58jjO0uIhkuNkP278nh5X2DTNjluHSX j+2pkrsMgmUyzOnct+w5KhNHSdokktZgu8a0K8dTo/ze/wbplFSawPxZFk3C4mitvq 1GQJR6o7dBIQQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A803118005B for ; Thu, 13 Mar 2025 20:39:13 +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.5 required=5.0 tests=BAYES_05,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: Received: from mail-qv1-f43.google.com (mail-qv1-f43.google.com [209.85.219.43]) (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, 13 Mar 2025 20:39:11 +0000 (UTC) Received: by mail-qv1-f43.google.com with SMTP id 6a1803df08f44-6dd1962a75bso11627286d6.3 for ; Thu, 13 Mar 2025 13:41:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741898504; x=1742503304; 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=lLVpAzzgDqyGQDvlY08WO6uswUbJ4JUjJlmKMWi6JLU=; b=XkohKgdlPW14EhH7srS+U518P+xfAt+YXCkMq6hGH0X8SiNXyFNC6w7Xh2UwwQNZcA nsPPHIPOzRvJuvii7DI03y77RXnvrV+/9XwGcUWl6TWWFnJxbVI9MI5F3wMQHT/AXVzj Aa6IWwUFCy5KvSZFI7KZNGUe0y5ACpm8SYpuo76fY3COnNHtBbKrq2oYxduE02C94vru aE0TjRZVDLltpaoKUfyP8tj9hNOy2jMI4WlaTdCIakDmKNgROI3/59Wu7lNiU5OT1hOI n3trrkYNsoywCWpzqhfH88441YPMvrBVDq00s16sXU0p7qgg3j0s7l99QCnKakn0+f6q Q28w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741898504; x=1742503304; 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=lLVpAzzgDqyGQDvlY08WO6uswUbJ4JUjJlmKMWi6JLU=; b=lRt9lc9xegHfrw8dVOMKzIhFIFoAQ0VnDAp/Vut3VOyU5+iI17s28aoYb1X78WLFHR K0dTMukCaDik0CwfEN13bXP303rwxUAW4x7p2VUCTUjJfYsBgV4y+8dvBf19obGgHNln 7AOxe0/2dSxqWEGDBeqouux3mwIL0b9l9QRzS8l0C3edB6h6/pPQ0kJ3gZ/TTh4YpAyJ CcYvbBMtt4vsZd037d5DRNRWsw1PwkGSSMrb1JWRAJJ7skSFyPtX/rSoOZYr6NoU9otc LPltkMF1EH2qP5T7SxnXzizul3DIpsOB5zclFBvx+pihvXHLUkzoauQeEUlaROSW6rJR pd/g== X-Gm-Message-State: AOJu0Yyf/dFD4lLyRI+rKiPU3n0l6Qav9JfXWiJ3F9kKmel/jl8NFZvX 7Ymz8wt/GbykyxcSyDwFDPvZ7Hf93AmCkha1aYowp84u1ZiIPlEjgtKS7mQlrKup5K1isjR3mxA r1Xq+W+UGYHjmZxs4gjV2SfDLGObwc/YUBd0= X-Gm-Gg: ASbGncsaYb1eZobu6S/8QYqUP7zefA68b1KFVaCALS10SbeyA7JrX4pQrTOJGUS99bj wwyJk0Q3UzqsQp27acYiDudtTphTvsIXVU2YZuP33q3Hvx7awRP+kRTrzZu2KAzZs75Vy9iVRyA zGVwFXM/le7mjQoVaK3VtoZST6d+4bB70XOIGPIT7f6kRMXzcLda5VJ9WW2E0= X-Google-Smtp-Source: AGHT+IGYAHNEoUkRqvlhkY+AhUkXeF4cB70Fx2STMSCZN2voZNQr/hwV/2PQ+0UJugyydm7JIlJ/f5uBwHqaKwnscGk= X-Received: by 2002:a05:6214:5006:b0:6ea:d604:9e59 with SMTP id 6a1803df08f44-6eae79b5da9mr19137596d6.9.1741898503695; Thu, 13 Mar 2025 13:41:43 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <2935d0e2-ddc4-447c-ab37-c9b7337b8b60@app.fastmail.com> <0d94bf183543ee9948fcd31337198438@bastelstu.be> In-Reply-To: Date: Thu, 13 Mar 2025 21:41:41 +0100 X-Gm-Features: AQ5f1Jpj91-ATL_FgMAmuRKGhS8Fvi3MXC36_5ghJpoajlOzvLfJGb9IHCOb7m4 Message-ID: Subject: Re: [PHP-DEV] Re: RFC: short and inner classes To: PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: tovilo.ilija@gmail.com (Ilija Tovilo) Hi Rob On Thu, Mar 13, 2025 at 1:57=E2=80=AFPM Rob Landers wro= te: > > > the proposal is > > currently quite complex. > > Most of this is just describing how classes work already and going in-dep= th on where there may be confusion -- there are no significant changes to h= ow classes actually work. The actual changes to the engine are basically ju= st visibility rules, some syntax changes (to allow nesting `class` inside a= nother class), and handling the new operator. The hard part is explaining h= ow classes work, because they don't really have a defined behavior. In othe= r words, I cannot just say "the way this works doesn't change anything." Well, you cut out the examples I gave: > It has a custom operator, it deals with shadowing, LSP, runtime resolutio= n and more, in addition to visibility which is the actual goal. Those are u= nrelated to existing behavior, they are introduced in the proposal. * The custom operator and runtime resolution is not something that technically needs to be there. The name of class Foo { class Bar {} } could simply be Foo\Bar. I've mentioned before that this does not work with PSR-4, but there's no reason it can't work with autoloading at all. An extended autoloading spec could recursively search Foo/Bar/Baz.php, then Foo/Bar.php, and so forth. Given this happens only when loading the class, and nesting would usually be limited in quantity and amount, that seems like a reasonable solution, and Composers optimized autoloader could avoid it entirely. This would also solve the same issue for sealed classes, assuming they're named in a similar fashion. * By shadowing I referred to static:>MyClass. This makes it more modular, but it's also another layer of complexity and indirection. You haven't really provided a reasoning and examples of how this could be used. It's also not clear if this can be prevented. The inner class can be marked as final, but that wouldn't stop you from shadowing the inner class without extending it. Similarly, static:>MyClass would have no type guarantees, given that it can be shadowed by any classes, not just classes that are compatible. class Outer { protected class Inner { public static function innerTest() {} } public static function outerTest() { static:>Inner::innerTest(); } } class OuterV2 extends Outer { protected class Inner {} // This breaks outerTest() } * LSP issues have been mentioned before. You can use self:>Inner in method signatures even if the inner classes are private. The method could be called from sub-classes, but they couldn't ever override it, since there's no way to satisfy the parent signature. This makes it implicitly final. Not technically a problem, just odd. As mentioned, maybe there are additional use-cases this complexity can cover, but the RFC doesn't give many examples. If the primary reason for this complexity is just visibility, then I don't think this is the simplest and best way in which that goal could be achieved. > > They might > > still be ok if they are extremely simple > > And now you can understand why they WERE just simple classes (short class= es). So, you can see why I originally bundled them together because of this= EXACT argument. :sigh: The arguments above are not limited to complex classes. Simple classes would apply to. * The :> operator is still something new that I don't believe needs to be t= here. * Shadowing simple classes can still cause incompatibilities between constructors. * The LSP issue applies. * As soon as we try to add support for complex classes, we'll run into the same questions again. Thinking ahead is always worth it, to prevent us from running into issues later. Doesn't mean everything needs to land at the same time ofc. Ilija