Re: Module or Class Visibility, Season 2

From: Date: Sun, 25 May 2025 22:17:56 +0000
Subject: Re: Module or Class Visibility, Season 2
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
On 25/05/2025 21:28, Larry Garfield wrote:
Even if we develop some way such that in Foo.php, loading the class \Beep\Boop\Narf pulls from /beep/boop/v1/Narf.php and loading it from Bar.php pulls the same class from /beep/boop/v2/Narf.php, and does something or other to keep the symbols separate... Narf itself is going to load \Beep\Boop\Poink at some point. So which one does it get? Or rather, there's now two Narfs. How do they know that the v1 version of Narf should get the v1 version of Poink and the v2 version should get the v2 version.
The prefixing, in my mind, has nothing to do with versions. There is no "v1" and "v2" directory, there are just two completely separate "vendor" directories, with the same layout we have right now. So it goes like this: 1. Some code in wp-plugins/AlicesCalendar/vendor/Beep/Boop/Narf.php mentions a class called \Beep\Boop\Poink 2. The Container mechanism has rewritten this to \__Container\AlicesCalendar\Beep\Boop\Poink, but that isn't defined yet 3. The isolated autoloader stack (loaded from wp-plugins/AlicesCalendar/vendor/autoload.php) is asked for the original name, \Beep\Boop\Poink 4. It includes the file wp-plugins/AlicesCalendar/vendor/Beep/Boop/Poink.php which contains the defintion of \Beep\Boop\Poink 5. The Container mechanism rewrites the class to \__Container\AlicesCalendar\Beep\Boop\Poink and carries on When code in wp-plugins/BobsDocs/vendor/Beep/Boop/Narf.php mentions \Beep\Boop\Poink, the same thing happens, but with a completely separate sandbox: the rewritten class name is \__Container\BobsDocs\Beep\Boop\Poink, and the autoloader was loaded from wp-plugins/BobsDocs/vendor/autoload.php Unless explciitly specified as an "import" or "export", any reference to any class name is prefixed in the same way, and loaded with the isolated autoloader stack. To the host application, and any other plugins, the code inside the "wp-plugins/AlicesCalendar/vendor" and "wp-plugins/BobsDocs/vendor" directories is entirely hidden. -- Rowan Tommins [IMSoP]

Thread (50 messages)

« previous php.internals (#127458) next »