i wanted integrate app google callendar.
added google php api libraries/google.
libraries/google/autoload.php is:
define ('google_lib_path', base_p . 'libraries/google/'); set_include_path( get_include_path() . path_separator . google_lib_path ); spl_autoload_register( function ($classname) { $classpath = explode('_', $classname); if ($classpath[0] != 'google') { return; } // drop 'google', , maximum class file path depth in project 3. $classpath = array_slice($classpath, 1, 2); $filepath = google_lib_path . implode('/', $classpath) . '.php'; echo $filepath .'<br>'; if (file_exists($filepath)) { require_once($filepath); } } ); output is:
/home/users/page/libraries/google/service/calendar.php /home/users/page/libraries/google/service.php /home/users/page/libraries/google/service/resource.php /home/users/page/libraries/google/client.php /home/users/page/libraries/google/collection.php /home/users/page/libraries/google/model.php fatal error: class 'google_config' not found in /home/users/page/libraries/google/client.php on line 77 after adding 1 call starts loading config, stops @ other
define ('google_lib_path', base_p . 'libraries/google/'); set_include_path( get_include_path() . path_separator . google_lib_path ); spl_autoload_register( function ($classname) { // same above } ); $x = new google_config; // added line output is:
/home/users/page/libraries/google/config.php /home/users/page/libraries/google/service/calendar.php /home/users/page/libraries/google/service.php /home/users/page/libraries/google/service/resource.php /home/users/page/libraries/google/client.php /home/users/page/libraries/google/collection.php /home/users/page/libraries/google/model.php fatal error: class 'google_auth_oauth2' not found in /home/users/page/libraries/google/client.php on line 614 autoloader seems work when wants. or there magic not know about?
php version 5.4.36-0+tld0
tried class "google_config" not found , spl_autoload_register() not working on server
edit: base_p defined as: dirname(__file__).'/' in main dir.
edit2: tried including classes manually. autoloader stops working after: libraries/google/model.php loaded. if load model.php before else (right after registering autoloader) not seem break autoloader. still stops after few autoloads.
it's old project, , found culprit:
function __autoload($class_name) { $dir = dirname(__file__).'/'; if (file_exists($dir.'classes/'. $class_name . '.php')) require_once $dir.'classes/'. $class_name . '.php'; } changing to:
spl_autoload_register( function ($class_name) { $dir = dirname(__file__).'/'; if (file_exists($dir.'classes/'. $class_name . '.php')) require_once $dir.'classes/'. $class_name . '.php'; ); fixed other autoloader.
moral? never mix __autoload() , spl_autoload_register()
never use __autoload() deprecated , example shows, can break things.
(or stated http://php.net/manual/en/language.oop5.autoload.php)
hope someday.
Comments
Post a Comment