2012/11/6 Laupretre François <francois.laupre...@francetv.fr> > > I've asked this question for a while (one, or two years ago or so). > > Must say, that I didn't remember the answer, but I would like to see > > autoloading for namespace-constants and functions too :) > > I proposed extending the autoload mechanism to functions and constants > several times since I released Automap. Automap ( > http://automap.tekwire.net) is a map-based PHP autoloader. It includes a > source scanner which analyzes source files and builds a map file from the > symbols it finds. This process already registers functions and constants, > as well as classes. So, it is ready to resolve functions and constants (and > it was recently improved to support namespaces). > > After I released Automap (back in 2006 !), I had planned to finish the > work, i.e. create new hooks in the PHP core to autoload undefined > functions/constants. Unfortunately, when I proposed this on the list, the > reaction was mostly negative and the proposal was rejected. IMO, it comes > from a misconception about autoloaders, as most autoloaders are path-based, > and such a mechanism imposes a restriction of one symbol per file, which > makes it useless in practice for functions and constants. So, the idea of > extending the autoload *features* was rejected because of current > autoloader *implementations*. > > There may also be a global feeling among core devs that non-OO programming > belongs to the past and shouldn't be encouraged... >
I have the same feeling and I don't really like it as this encourages to treat functions and (static) methods identically (but they aren't). > > I hope you find more support on this than I had. Technically speaking, it > would be easy to extend autoloading to functions and constants. It can even > be done without BC breaks, combining 'old-style' and 'new-style' > autoloaders without ambiguity (adding a second argument to the autoload > hook, and checking the number of args declared by the function). > Thats not even required, if you fixate (--> default value) the second parameter to "class" all existing loaders will behave, like they did before. Ive found my old thread [1] and somewhere in there I suggested something like that as a possible solution [1] http://marc.info/?l=php-internals&m=131166835320805 > A summary of the talk we had (6 years ago !) : > http://devzone.zend.com/616/zend-weekly-summaries-issue-306/ > > Regards > > François > -- github.com/KingCrunch