Re: Re: Why isn't `spl_autoload` called for functions?

From: Date: Tue, 06 Nov 2012 19:17:11 +0000
Subject: Re: Re: Why isn't `spl_autoload` called for functions?
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-63765@lists.php.net to get a copy of this message
On Tue, Nov 6, 2012 at 11:15 AM, Laupretre François < 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.

« previous php.internals (#63765) next »