Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127345 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 lists.php.net (Postfix) with ESMTPS id 4A89A1A00BC for ; Tue, 13 May 2025 18:48:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1747161953; bh=xE1upQJ+IzXCCulPUCPf5hXBx/fUEkjyh/2BLSBJCXc=; h=References:In-Reply-To:From:Date:Subject:To:From; b=cLUXVNWBA19DF/TOVzx4nnuukWYBoYYesrgYJVWt8eYiPmKd1oMBML1Xa4gMbi7WQ DN+aPYhoT9mqVKso5a5Xdl/sfLX7k6y84qYsZrI3cBMM4DAMVoAyiUkitvIMLwXIwM GpWmJSeNR4s53qdZR9RzoDhiTLvgdlpezaLaRik7E9lSrfK8he9jtY26xuck+nhzrP b31CcNxY0LOR31omQWp4UL4Na+LRAW6ST+x0fexZwJnXx6LZtEk5CABU6nrp/JIumJ HZzjqidK/IqzNoFa+6GEcexrr2Dw8q90vMZDb+zGBxaAxEkssm4ZP8/2BVE1UbefEO GUeaWNpoGLnuw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9DEAF18056B for ; Tue, 13 May 2025 18:45:50 +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.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,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: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail-qv1-f47.google.com (mail-qv1-f47.google.com [209.85.219.47]) (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 ; Tue, 13 May 2025 18:45:49 +0000 (UTC) Received: by mail-qv1-f47.google.com with SMTP id 6a1803df08f44-6f6e5172eeaso52477866d6.2 for ; Tue, 13 May 2025 11:48:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1747162080; x=1747766880; darn=lists.php.net; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=WsLQ/yP4rEjeI1jvBq2ugMZ2jq7Xe9y+gsqvpgt1XNs=; b=CE7zCYo9pkftQdLwiIR4o1fCFMQ+UMigej8C8Fk6JGlh9QcdFL6bFqPYLZShhUkv2y VvEaNIl7ZNAOfvXg8n0jaCzpZ7CZF8zFIeYgxhd90dDxLdeN9GpNlzQfyEmkGKZeG8iv ikDFzOY4xjZUTNkvFvxT6Oe0VVPVi2dXfMEQA6RtgnIeWXT3eYsln+7FvuQlXRD3/M2u Vo67qNn5/CMmB3vGsCqOfFFDGsP8dSAJeRjr11XfGXrRO11XopCnk5Adf+jaOyq+5gvS 0t3zlEw0to3HB5umueJvQDGM1Y4w0ZMX6eCbvoDsPKGz3tlcT9mdw6hdBBzTH6Gt0TKG UpYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747162080; x=1747766880; h=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=WsLQ/yP4rEjeI1jvBq2ugMZ2jq7Xe9y+gsqvpgt1XNs=; b=vwx4nOX9IiZXdiW8ke45ragGc7fuEkg8qI/DLw9O+3ezQkwMFUa53Z9mvbd9h0lzJs LF7xmn+RAtmG42ExZnAq5/qUQOYHk1WbksnEM/i/X2PmOOCwov3B81s5TPUD92q878PS dQWQte0/PPIosaUvT3VMumgjYFtLWjIAIEP6oee/nz/Nh4CabEN/nHgPfHAdPIjWP7dp 1v/qKIGmV4kbRuynEHfpRmQIrzoiyWD8/XcyVvyscLOL/ZTQvn460rPAILjIN0Y06TLG 9xZV+uR5vANLTUVmFou4pl9NWKJv5Fvq/Uo66aY+3lhRw9OmFiXDXi3UdX4L8qcBRB83 iMWw== X-Gm-Message-State: AOJu0YyGVBv1n+mduoy2WN5pP5+wE7UmS63pWD8PgOGMeOx6HCgDUn1/ pU43o/UyqVoZOVNSsJPY8K0nTsnc8G4yoJV6aifDlRn79yjKZW+1udy3soF6ZKqkd+FQ92FDkq7 A4bqQY88EVIu/j5XIGiYus/X0IrhkiQ== X-Gm-Gg: ASbGncsmerVIb0KJj0O/3W2j12HcN9fWe1FiM9C69KkPVXyrnbFFIhe4LdPzoeJ4MQr njs8016d6K2CNg3QFWeo+0+YOkDJ25QPLd5yobNpRLQl2kHdX+wPu3/30P83W0wVtbYyC9uO4Ky 1zfkzAuJ2zgwLwKV7R4voullU8VjGh6LDEr9u9HWD6yyEothcF+ObEM7fU53VayJ8= X-Google-Smtp-Source: AGHT+IEO2xBOuUqyo6Tgp+S5urvwLwDZeCIO2NXc2yyP1KZCtdfn2xBfZlzeBF5ApOyiL5bL2L0Mzn8nSNA8uRxzW5E= X-Received: by 2002:ad4:5aea:0:b0:6e8:9e8f:cfb with SMTP id 6a1803df08f44-6f896e3385dmr7401166d6.24.1747162079607; Tue, 13 May 2025 11:47:59 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 13 May 2025 14:47:47 -0400 X-Gm-Features: AX0GCFuI1DMc7NNXhu5R17F80alf0DVQLsoLKHyKmu4TKrImhuP5EmO2mZJrmXk Message-ID: Subject: Re: [PHP-DEV] Module or Class Visibility, Season 2 To: PHP internals Content-Type: multipart/alternative; boundary="0000000000001ec1f9063508df47" From: tendoaki@gmail.com (Michael Morris) --0000000000001ec1f9063508df47 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, May 13, 2025 at 11:31=E2=80=AFAM Deleu wrote: > Hi! > > This would allow public, private and protected classes in a way that I > believe to be useful for the large ecosystem that surrounds Composer. Fro= m > my extremely limited understanding of the engine, I think the easy/natura= l > step would be to allow private/protected classes to be *received* outside > its namespace because a type declaration does not trigger autoload. > This has been discussed before - making Namespaces something beyond what they are - a convenience string replace. That is given ```php namespace foo; use otherns\boo; function bar () {} bar(); boo(); ``` The engine quietly rewrites as ```php function foo\bar () {} foo\bar(); otherns\boo(); ``` The engine doesn't store any notion of namespace directly, it's just a string replace on the symbol table. And if I recall correctly this is also the reason that \ is the namespace operator - the original proposal was for namespaces to have the :: operator, same as static classes, but late in the implementation it was found that there were disambiguation problems and the choice was made to use the \ operator rather than solve those problems. I assume the problems were judged to be intractable, but I can't say for sure= . Also, a namespace block could appear anywhere, so if a stubborn programmer really wanted to get access to a private or protected block they could put a namespace block into their own code with the same namespace. This also doesn't isolate a module with shared dependencies from changes to those dependencies. This makes composer libraries impossible to use effectively in the absence of a mechanism for coordinating those conflicts from the core. And for worse, the WP core team doesn't want to provide such. And yes, it really isn't the PHP dev team's direct responsibility to step in and *directly* fix that problem. Indirectly perhaps? Only if it is a benefit to everyone who uses the language. Neither PHP nor JavaScript deal with directories or other file collections. We have to look to Java and its jar files or golang modules for examples of this. And no, the PSR standard of mapping namespaces to directories has nothing to do with how the engine itself sees packages, namespaces, or the world. In truth it sees none of these because they don't exist in the runtime in any meaningful way that I'm aware of. Phar perhaps? I know little of that system beyond the fact is the manner in which composer and a few other libs are distributed. I sense, and I could be wrong here, that there is no appetite for moving beyond the one file at a time model. So the system I proposed last go round was still a one file solution. Other ideas I've seen kicked around - file based privacy. In this schema a file can declare itself private (public is the assumed and Backward compatible default) and then mark exceptions to this as public. But for this to truly be useful I fear some file structure awareness would be needed and again, at the moment, PHP doesn't do that. A very long time ago I proposed a require into namespace mechanism. The engine by default attaches all incoming namespaces to the root /. I suggested (because I naively thought require was a function construct, not a statement, and was ignorant of the difference at the time) that "target namespace" could be the second argument of require and if provided all the symbols established by that file become attached to that namespace. This could only work if the autoloader correctly dispatched symbols to the correct namespaces, and I don't have a clue how it could do that. The need of the plugin community is code that just plugs into the app and doesn't need to care about what the other applications are doing. This is currently possible only if the plugin provides all of its own code and if it does use composer libraries, it resorts to monkey-typing to change the names of all the symbols to something prefixed with the plugin name to avoid collisions. This approach is NOT optimal but it is the only one at present. However, an important question is whether this is enough groundwork that > could lead to optimizations that have been discussed when the topic of > module is brought up. For instance, if type-hint outside the module is > disallowed, could that make it easier to pack and optimize an entire modu= le > if we could instruct PHP how to load all symbols of a namespace all at > once? I don't know. > Doing that would likely involve giving the engine some notion of directory, again as Java does with JAR files, and PHP might do in PHAR files but I know embarrassingly little about them. Could the existing PHAR structure be used in some way for a starting point on this? I just don't know, not without research. --0000000000001ec1f9063508df47 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Tue, May 13,= 2025 at 11:31=E2=80=AFAM Deleu <d= eleugyn@gmail.com> wrote:
Hi!

This wo= uld allow public, private and protected classes in a way that I believe to = be useful for the large ecosystem that surrounds Composer. From my extremel= y limited understanding of the engine, I think the easy/natural step would = be to allow private/protected classes to be received=C2=A0outside it= s namespace because a type declaration does not trigger autoload.

This has been discussed before - making= Namespaces something beyond what they are - a convenience string replace.= =C2=A0 That is given

```php
namespace fo= o;
use otherns\boo;

function bar () {}
bar();
boo();
```
The engine quietly= rewrites as
```php
function foo\bar () {}
foo\bar();
otherns\boo();
```
The engine doesn't store any notion of namespace directly,= it's just a string replace on the symbol table. And if I recall correc= tly this is also the reason that \ is the namespace operator - the original= proposal was for namespaces to have the :: operator, same as static classe= s, but late in the implementation it was found that there were disambiguati= on problems and the choice was made to use the \ operator rather than solve= those problems. I assume the problems were judged to be intractable, but I= can't say for sure.

Also, a namespace block c= ould appear anywhere, so if a stubborn programmer really wanted to get acce= ss to a private or protected block they could put a namespace block into th= eir own code with the same namespace.=C2=A0

This a= lso doesn't isolate a module with shared dependencies from changes to t= hose dependencies.=C2=A0 This makes composer libraries impossible to use ef= fectively in the absence of a mechanism for coordinating those conflicts fr= om the core.=C2=A0 And for worse, the WP core team doesn't want to prov= ide such. And yes, it really isn't the PHP dev team's direct respon= sibility to step in and *directly* fix that problem.=C2=A0 Indirectly perha= ps? Only if it is a benefit to everyone who uses the language.
Neither PHP nor JavaScript deal with directories or other file= collections. We have to look to Java and its jar files or golang modules f= or examples of this. And no, the PSR standard of mapping namespaces to dire= ctories has nothing to do with how the engine itself sees packages, namespa= ces, or the world. In truth it sees none of these because they don't ex= ist in the runtime in any meaningful way that I'm aware of. Phar perhap= s? I know little of that system beyond the fact is the manner in which comp= oser and a few other libs are distributed.

I sense= , and I could be wrong here, that there is no appetite for moving beyond th= e one file at a time model. So the system I proposed last go round was stil= l a one file solution.

Other ideas I've seen k= icked around - file based privacy. In this schema a file can declare itself= private (public is the assumed and Backward compatible default) and then m= ark exceptions to this as public.=C2=A0 But for this to truly be useful I f= ear some file structure awareness would be needed and again, at the moment,= PHP doesn't do that.

A very long time ago I p= roposed a require into namespace mechanism.=C2=A0 The engine by default att= aches all incoming namespaces to the root /.=C2=A0 I suggested (because I n= aively thought require was a function construct, not a statement, and was i= gnorant of the difference at the time) that "target namespace" co= uld be the second argument of require and if provided all the symbols estab= lished by that file become attached to that namespace.=C2=A0 This could onl= y work if the autoloader correctly dispatched symbols to the correct namesp= aces, and I don't have a clue how it could do that.

The need of the plugin community is code that just plugs into the app= and doesn't need to care about what the other applications are doing.= =C2=A0 This is currently possible only if the plugin provides all of its ow= n code and if it does use composer libraries, it resorts to monkey-typing t= o change the names of all the symbols to something prefixed with the plugin= name to avoid collisions.=C2=A0 This approach is NOT optimal but it is the= only one at present.

However, an important question is wh= ether this is enough groundwork that could lead to optimizations that have = been discussed when the topic of module is brought up. For instance, if typ= e-hint outside the module is disallowed, could that make it easier to pack = and optimize an entire module if we could instruct PHP how to load all symb= ols of a namespace all at once? I don't know.
<= div>
Doing that would likely involve giving the engine some n= otion of directory, again as Java does with JAR files, and PHP might do in = PHAR files but I know embarrassingly little about them. Could the existing = PHAR structure be used in some way for a starting point on this? I just don= 't know, not without research.

--0000000000001ec1f9063508df47--