1

I got installed MaxMind's GeoIp2 => https://github.com/maxmind/MaxMind-DB-Reader-php

Also php extension https://github.com/maxmind/libmaxminddb for faster lookup

Everything works just fine when i am using it like this:

require_once '/pathto/Composer/vendor/autoload.php';
use GeoIp2\Database\Reader;

$reader = new Reader('/pathto/GeoLite2-Country.mmdb');
$record = $reader->country('8.8.4.4');

The problem starts when i am trying to use it on same php file where i am also using my own autoloader:

function __autoload($class_name) {
  $p = explode("\\", $class_name);
  require_once 'pathto/'.$p[2].'.class.php';
}

It seems like this 2 autoloaders collide each other and in fact i cannot use GeoIp2 in file mixed with my classes.

How can i solve this annoying problem? Thank you so much in advance.

Oleg Popov
  • 2,464
  • 1
  • 17
  • 15
  • 1
    As I remember MaxMind is PSR-4. please confirm that with your composer autoloader. This should help you. https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md – masterFly Aug 31 '16 at 07:50
  • Yeah, thank you. Actually based on your comment finally i found a solution exactly with PSR 4. Thank you. – Oleg Popov Sep 04 '16 at 01:26

1 Answers1

0

The problem has been solved by using:

spl_autoload_register();

Here is simple example:

function base_autoload($class_name) {

  $p = explode("\\", $class_name);
  require_once '/mydir/'.$p[2].'.class.php';

}

spl_autoload_register('base_autoload');
Oleg Popov
  • 2,464
  • 1
  • 17
  • 15