anevins Posted September 1, 2012 Share Posted September 1, 2012 Hello, I'm using Geocoder (http://geocoder-php.org/) in my application. I've installed it using the steps provided on the website. Problem: When I run the application, I receive the error; Fatal error: Class 'Buzz\Browser' not found in D:\xampp\htdocs\dmp\geocoder\src\Geocoder\HttpAdapter\BuzzHttpAdapter.php on line 31 Line 31: $this->browser = new Browser(); Entirety of BuzzHttpAdapter.php: http://pastebin.com/GBDaWhWR I've updated my PHP to the latest version. I don't know how to solve this, would anyone be able to help? Quote Link to comment https://forums.phpfreaks.com/topic/267889-geocoder-issue-class-not-found/ Share on other sites More sharing options...
ignace Posted September 1, 2012 Share Posted September 1, 2012 That is due to php being unable to locate the class. Make sure you have something like this in your bootstrap file: set_include_path( implode(PATH_SEPARATOR, array('.', realpath('path/to/library')) ); spl_autoload_register(function($className) { $className = ltrim($className, '\\'); $fileName = ''; if ($lastNsPos = strripos($className, '\\')) { $namespace = substr($className, 0, $lastNsPos); $className = substr($className, $lastNsPos + 1); $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; } $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; require $fileName; }); Quote Link to comment https://forums.phpfreaks.com/topic/267889-geocoder-issue-class-not-found/#findComment-1374519 Share on other sites More sharing options...
anevins Posted September 1, 2012 Author Share Posted September 1, 2012 In my autoload.php file, I have spl_autoload_register(function($className) { $className = ltrim($className, '\\'); if (0 != strpos($className, 'Geocoder')) { return false; } $fileName = ''; $namespace = ''; if ($lastNsPos = strrpos($className, '\\')) { $namespace = substr($className, 0, $lastNsPos); $className = substr($className, $lastNsPos + 1); $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; } $fileName = __DIR__ . DIRECTORY_SEPARATOR . $fileName . $className . '.php'; if (is_file($fileName)) { require $fileName; return true; } return false; }); I've tried adding set_include_path( implode(PATH_SEPARATOR, array('.', realpath('path/to/library')) ); But I don't know the library or directory I'm supposed to be pointing to, because I've tried looking for this class but not found it. Quote Link to comment https://forums.phpfreaks.com/topic/267889-geocoder-issue-class-not-found/#findComment-1374529 Share on other sites More sharing options...
ignace Posted September 1, 2012 Share Posted September 1, 2012 https://github.com/kriswallsmith/Buzz Your directory structure should look something like: vendor `- Buzz `- Geocoder autoloader.php In your autoloader then should be: set_include_path( implode(PATH_SEPARATOR, array('.', realpath('vendor')) ); Quote Link to comment https://forums.phpfreaks.com/topic/267889-geocoder-issue-class-not-found/#findComment-1374536 Share on other sites More sharing options...
anevins Posted September 2, 2012 Author Share Posted September 2, 2012 I'm now using this autoloader.php file <?php // autoload.php generated by Composer require_once __DIR__ . '/composer' . '/autoload_real.php'; return ComposerAutoloaderInit::getLoader(); But the error persists. I've tried adding set_include_path( implode(PATH_SEPARATOR, array('.', realpath('vendor')) ); But I do not follow the exampled directory structure you stated and I see no error change. The following link shows my directory structure: http://postimage.org/image/nvco6lljj/full/ I appreciate the help by the way. Quote Link to comment https://forums.phpfreaks.com/topic/267889-geocoder-issue-class-not-found/#findComment-1374740 Share on other sites More sharing options...
ignace Posted September 3, 2012 Share Posted September 3, 2012 If your class is named like this: namespace Foo\Bar; class Bat {} And it is located in app/library/Foo/Bar/Bat.php. Then your include path should be: set_include_path( realpath('app/library') ); So that when PHP looks for Foo\Bar\Bat it will find it in app/library/Foo/Bar/Bat.php. Change your directory structure or alter the include path so that it matches with where your classes live. Quote Link to comment https://forums.phpfreaks.com/topic/267889-geocoder-issue-class-not-found/#findComment-1374791 Share on other sites More sharing options...
anevins Posted September 3, 2012 Author Share Posted September 3, 2012 So my I want to set the include path to the directory of my file that is not found? The browser.php file, from the original error Class 'Buzz\Browser' not found, has the namespace of Buzz. This is the directory of the Browser.php file D:\wamp\www\dmp\vendor\Buzz\lib\Buzz When I var_dump( realpath ( '../vendor/Buzz/lib/Buzz' ) ); I get string 'D:\wamp\www\dmp\vendor\Buzz\lib\Buzz' (length=36) And when I var_dump (set_include_path( ( realpath ( '../vendor/Buzz/lib/Buzz') ) ); I get string '.;C:\php\pear' (length=13) Here is my autoload.php file now <?php // autoload.php generated by Composer require_once __DIR__ . '/composer' . '/autoload_real.php'; set_include_path( ( realpath ( '../vendor/Buzz/lib/Buzz') ) ); return ComposerAutoloaderInit::getLoader(); And this is the browser.php file https://github.com/kriswallsmith/Buzz/blob/master/lib/Buzz/Browser.php Quote Link to comment https://forums.phpfreaks.com/topic/267889-geocoder-issue-class-not-found/#findComment-1374827 Share on other sites More sharing options...
Christian F. Posted September 3, 2012 Share Posted September 3, 2012 No, you'll want to set the path to where the file resides, minus the namespace part. So if the file does indeed reside in the above location, then you'll want to set the include path to "../vendor/Buzz/lib". The rest is supplied by the namespace. Quote Link to comment https://forums.phpfreaks.com/topic/267889-geocoder-issue-class-not-found/#findComment-1374865 Share on other sites More sharing options...
anevins Posted September 3, 2012 Author Share Posted September 3, 2012 I now understand how to construct the correct realpath. So here's my autoload.php file again <?php // autoload.php generated by Composer //var_dump( realpath('../vendor/Buzz/lib'));exit; set_include_path( ( realpath ( '../vendor/Buzz/lib') ) ); require_once __DIR__ . '/composer' . '/autoload_real.php'; return ComposerAutoloaderInit::getLoader(); I was thinking maybe I put this 'set_include_path' function using the wrong autoload file. So I've tried putting it in all of them but it's the same issue. This is the directory the autoload.php file is in D:\wamp\www\dmp\vendor This is the directory the other autoload files are in D:\wamp\www\dmp\vendor\composer This, again sorry, is the directory the Browser.php file is in D:\wamp\www\dmp\vendor\Buzz\lib\Buzz Quote Link to comment https://forums.phpfreaks.com/topic/267889-geocoder-issue-class-not-found/#findComment-1374876 Share on other sites More sharing options...
anevins Posted September 10, 2012 Author Share Posted September 10, 2012 Thanks for your help everyone. The solution can be found here; https://github.com/willdurand/Geocoder/issues/82 RESOLVED Quote Link to comment https://forums.phpfreaks.com/topic/267889-geocoder-issue-class-not-found/#findComment-1376746 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.