RE: [PHP-DEV] Re: [PHP-WEBMASTER] Why isn't `spl_autoload` called for functions?
| From: | Laupretre François | Date: | Tue, 06 Nov 2012 23:35:13 +0000 |
| Subject: | RE: [PHP-DEV] Re: [PHP-WEBMASTER] Why isn't `spl_autoload` called for functions? | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-63769@lists.php.net to get a copy of this message | ||
You're right. The argument of 'one symbol per file' is wrong.
When I find the time, I'll consider writing an RFC and a patch for this. But, before, I'd
like to get more support on this from list members as, IMO, most are still opposed to this
extension.
De : Levi Morrison [mailto:morrison.levi@gmail.com]
Envoyé : mardi 6 novembre 2012 20:17
À : Laupretre François
Cc : Sebastian Krebs; PHP internals list; petercowburn@gmail.com; Nikita Popov
Objet : Re: [PHP-DEV] Re: [PHP-WEBMASTER] Why isn't
spl_autoload called for
functions?
On Tue, Nov 6, 2012 at 11:15 AM, Laupretre François <francois.laupretre@francetv.fr<mailto:francois.laupretre@francetv.fr>>
wrote:
A summary of the talk we had (6 years ago !) : http://devzone.zend.com/616/zend-weekly-summaries-issue-306/
If functions and classes use the same autoloader, then you can use a function to filename mapping.
It's not as bad as people make it sound. We've gotten accustomed to doing things like
this over the last few years.
If they don't use the same autoloader:
1. Put the functions in file called function.php inside the folder of the
corresponding namespace.
2. Explode the parameter based on the namespace separator.
3. Replace the last item of the array with function.php (function is a
keyword and won't conflict with a class name).
4. Join it together and (conditionally) include it.
Something like this:
function autoloadFunctions($functionName) {
$parsedPath = explode('\\', $functionName);
$parsedPath[count($parsedPath) - 1] = 'function.php';
$fullPath = join(DIRECTORY_SEPARATOR, $parsedPath);
if (file_exists($fullPath)) {
require $fullPath;
}
}
I do more complex tasks every day at work. There are valid use cases and I'd love to see PHP
support them in some fashion.
Click here<https://www.mailcontrol.com/sr/UuaGo68pWmPGX2PQPOmvUjZx4naTDky4SyhVcCr1ioVMSlAqWmIR4HyEfMBpW7rnChnOsFIbW4PsVggzUgwWUw==>
to report this email as spam.