Destramic Posted February 6, 2011 Share Posted February 6, 2011 Im trying to load my classes though my autoloader load method but im having a problem with registering the class (spl_autoload_register) if anyone could tell me why? error: Fatal error: Uncaught exception 'LogicException' with message 'Passed array does not specify an existing static method' in C:\www\public\index.php:8 Stack trace: #0 C:\www\public\index.php(: spl_autoload_register(Array) #1 {main} thrown in C:\www\public\index.php on line 8 index.php spl_autoload_extensions('.class.php'); spl_autoload_register(array('Autoloader', 'load')); autoloader.class.php <?php class Autoloader_Exception extends Exception {} class Autoloader { public function load() { } } thanks Quote Link to comment https://forums.phpfreaks.com/topic/226900-spl_autoload-class/ Share on other sites More sharing options...
ignace Posted February 6, 2011 Share Posted February 6, 2011 public static function load() That solves your problem. If you pass an array with the first parameter being a string it is assumed to be a static call versus: $autoloader = new Autoloader(); spl_autoload_register(array(&$autoloader, 'load')); This will use the existing object and call a method load($class) upon it. Quote Link to comment https://forums.phpfreaks.com/topic/226900-spl_autoload-class/#findComment-1170804 Share on other sites More sharing options...
Destramic Posted February 6, 2011 Author Share Posted February 6, 2011 im getting an error... Fatal error: Class 'Autoloader' not found in C:\www\public\index.php on line 8 do i need to include the class aswell? Quote Link to comment https://forums.phpfreaks.com/topic/226900-spl_autoload-class/#findComment-1170825 Share on other sites More sharing options...
lastkarrde Posted February 7, 2011 Share Posted February 7, 2011 do i need to include the class aswell? Of course! Quote Link to comment https://forums.phpfreaks.com/topic/226900-spl_autoload-class/#findComment-1170854 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.