{"issue":{"created_at":"2011-11-29T07:56:33Z","state":"open","updated_at":"2011-11-29T07:56:40Z","user":{"gravatar_id":"256406243346b9253f8610fb1d1e05f6","id":1215373,"url":"https://api.github.com/users/importer","avatar_url":"https://secure.gravatar.com/avatar/256406243346b9253f8610fb1d1e05f6?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"importer"},"comments":6,"body":"Hi,\n\nIs there any special reason to use __autoload rather than spl_autoload?\n\nThis prevents extension developpers to add more autoloading functions.\n\n[Download the attachments](http://www.contao.org/tl_files/tickets/1451.zip \"Download the attachments of this ticket\")\n\n--- _Originally created by kik on January 24th, 2010, at 05:01pm (ID 1451)_","assignee":null,"id":2380173,"pull_request":{"patch_url":null,"html_url":null,"diff_url":null},"labels":[{"name":"Accepted","color":"6cc644","url":"https://api.github.com/repos/contao/test/labels/Accepted"},{"name":"Feature","color":"4183c4","url":"https://api.github.com/repos/contao/test/labels/Feature"},{"name":"framework","color":"e6e6e6","url":"https://api.github.com/repos/contao/test/labels/framework"}],"number":1451,"title":"spl_autoload","closed_at":null,"html_url":"https://github.com/contao/test/issues/1451","url":"https://api.github.com/repos/contao/test/issues/1451","milestone":null},"action":"created","comment":{"created_at":"2011-11-29T07:56:40Z","updated_at":"2011-11-29T07:56:40Z","user":{"gravatar_id":"256406243346b9253f8610fb1d1e05f6","id":1215373,"url":"https://api.github.com/users/importer","avatar_url":"https://secure.gravatar.com/avatar/256406243346b9253f8610fb1d1e05f6?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"importer"},"body":"> I don't quite understand your code. It does not actually load anything, does it?\nEhm... Yes, of course I forgot the loop (bad me, writing stuff here from memory instead of testing it first). :D\n\n```\n    // HOOK: include custom autoloaders\n    if (isset($GLOBALS[TL_AUTOLOAD]) && \n\n![](empty($GLOBALS[TL_AUTOLOAD]))\n    {\n        foreach($GLOBALS[TL_AUTOLOAD] as $function)\n            if(function_exists($function) && call_user_func($function, $strClassName))\n                return;\n    }\n```\n\nNow it loops over the registered autoloaders and calls them. Whenever an autoloader returns true, the entire function returns and we have the class.\n\nThe real loading would happen in the HOOKed function like the following:\nsomemodule/config/config.php (or wherever we might want to load this stuff from):\n\n```\n$GLOBALS[TL_AUTOLOAD][]='myClassLoader';\nfunction myClassLoader($strClassName)\n{\n    if($strClassName=='someClass')\n    {\n        include(TL_ROOT . '/path/to/somewhere/not/reachable/from/default/__autoload/filename.php')\n        return true;\n    }\n}\n```\n\nI have not tested yet if we could also omit the call_user_func and write it directly (should be possible from 5.2.6 on):\n\n```\n    // HOOK: include custom autoloaders\n    if (isset($GLOBALS[TL_AUTOLOAD]) && )empty($GLOBALS[TL_AUTOLOAD]))\n    {\n        foreach($GLOBALS[TL_AUTOLOAD] as $function)\n            if(function_exists($function) && $function($strClassName))\n                return;\n    }\n```\n\nMaybe we will be in need to define a new folder in system/config, where modules can place preloading config files so the autoloaders will indeed get included at the very beginning (should then be applied right before the loading of basic classes in initialize.php).\n\nI have to test this first. I will propose a patch within the next days.\n\n--- _Originally created by xtra on January 25th, 2010, at 09:54pm_","id":2920506,"url":"https://api.github.com/repos/contao/test/issues/comments/2920506"}}