libphonenumber php 找不到基类 Locale


libphonenumber php cannot find base class Locale

我正在使用 libphonenumber 的 php 实现

giggsey/libphonenumber-for-php

我需要它对用户输入的电话号码进行基本的感觉和有效性检查。

我已经获取了整个src/libphonenumber目录及其子目录并将其复制到我的项目中。 我不使用Composer,因为这只是我项目的一个元素,我希望现在不必爬上那个特定的学习曲线。 我将以下简单的自动加载器放在脚本的开头。

namespace libphonenumber;
spl_autoload_register('libphonenumber'myAutoloader');
function myAutoloader($className)
{
$path = 'libphonenumber/';
$parts=explode('''',$className,2);
$filename=str_replace('''','/',$parts[1]);
include $path.$filename.'.php';
}

自动加载程序工作正常,除了包含文件geocoding/Locale.php,其中包含单个类"Locale",如下所示;

class Locale extends 'Locale

我得到的错误是

PHP Fatal error:  Class 'Locale' not found in /var/www/luthor/php/libphonenumber/geocoding/Locale.php on line 6

我对 php 中的命名空间和 oo 很陌生。 我知道 Locale 是一个 php 类。 我的问题是为什么找不到

找到了答案。 使用语言环境需要安装 php 的国际扩展,请参阅以下问题

致命错误:在 ZF2 beta5 框架应用程序中找不到类"区域设置">