[英]How to use MaxMind's GeoIp2 in PHP with another autoloader?
I got installed MaxMind's GeoIp2 => https://github.com/maxmind/MaxMind-DB-Reader-php 我安装了MaxMind的GeoIp2 => https://github.com/maxmind/MaxMind-DB-Reader-php
Also php extension https://github.com/maxmind/libmaxminddb for faster lookup 另外php扩展https://github.com/maxmind/libmaxminddb以便更快地查找
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: 问题开始时,我试图在同一个php文件中使用它,我也在使用自己的自动加载器:
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. 看起来这两个自动加载器相互冲突,实际上我不能在与我的类混合的文件中使用GeoIp2。
How can i solve this annoying problem? 我该如何解决这个恼人的问题? Thank you so much in advance.
非常感谢你提前。
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');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.