Req #73202 [Opn->Wfx]: Pass origin (callee) as second parameter to autoloading implementations
| From: | requinix@php.net | Date: | Thu, 29 Sep 2016 09:35:08 +0000 |
| Subject: | Req #73202 [Opn->Wfx]: Pass origin (callee) as second parameter to autoloading implementations | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-204334@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73202&edit=1
ID: 73202
Updated by: requinix@php.net
Reported by: philippwrann at gmail dot com
Summary: Pass origin (callee) as second parameter to
autoloading implementations
-Status: Open
+Status: Wont fix
Type: Feature/Change Request
Package: SPL related
Operating System: all
PHP Version: Next Major Version
Block user comment: N
Private report: N
New Comment:
debug_backtrace in action: https://3v4l.org/ov3Me
I'd hardly call two lines of code a "hack" for a feature that is specialized at best
and conducive to unexpected bugs at worst.
Regardless, the side-by-side problem needs much more than just a second argument to the autoloader.
How will you have multiple versions of the same class available at once? How will PHP know that the
same class name needs the autoloader invoked multiple times from different paths, let alone which
one's code to execute when a class is referenced?
Not even Windows' SxS solution supports having multiple versions of a library running
concurrently for a single application.
Previous Comments:
------------------------------------------------------------------------
[2016-09-29 09:13:34] philippwrann at gmail dot com
In fact it would be possible at the moment if you use the debug_backtrace() function, but i thats
more a hack than a solution.
------------------------------------------------------------------------
[2016-09-29 08:54:38] philippwrann at gmail dot com
Description:
------------
At the moment it is not possible to implement dependency managers that can handle different versions
of the same package. If the callee (file location) would be provided as second parameter for
autoload callbacks a autoloading implementation could determine the correct version to load.
Some real world example:
You start a new composer based project and require some third party package.
That package requires another package, for example some api.
So long all is good
Now you require one more package, that requires the same package but in another version => not
possible.
A fix would be downwards compatible because the additional parameter would simply be ignored by
current implementations.
Test script:
---------------
// something like this
spl_autoload_register(function($className, $originPath){
get_real_autoloader($originPath)->load($className);
});
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=73202&edit=1