PHP - > NumberFormatter不工作

时间:2015-11-27 11:49:34

标签: php laravel laravel-5 laravel-5.1

我有php文件test.php:

use App\Classes\test_class;

$xml = new DOMDocument( "1.0", "ISO-8859-15" );
echo 'DOMDocument-ok<br/>';

$formatter = new NumberFormatter('en_US', NumberFormatter::DECIMAL);
echo 'NumberFormatter-ok<br/>';
new test_class();

和test_class.php:

class test_class{

    public function __construct()
    {
        $xml = new \DOMDocument( "1.0", "ISO-8859-15" );
        echo 'DOMDocument-ok<br/>';

        $formatter = new \NumberFormatter('en_US', \NumberFormatter::DECIMAL);
        echo 'NumberFormatter-ok<br/>';
    }

}

当我运行此代码输出时:

DOMDocument-ok
NumberFormatter-ok
DOMDocument-ok
NumberFormatter-ok

但是在我使用插件的插件“sebastian / money”中我得到了这个错误 “Symfony \ Component \ Debug \ Exception \ FatalErrorException(E_UNKNOWN) 救命 未找到“NumberFormatter”类

代码:

<?php
namespace SebastianBergmann\Money;

use NumberFormatter;

class IntlFormatter implements Formatter
{
    private $numberFormatter;
    public function __construct($locale)
    {
        $this->numberFormatter = new NumberFormatter(
            $locale,
            NumberFormatter::CURRENCY
        );
    }

对于行:

$this->numberFormatter = new NumberFormatter(
            $locale,
            NumberFormatter::CURRENCY
        );

编辑:

显然NumberFormatter不在所有Laravel应用程序内部工作,但我不知道为什么,有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

您可以将此用于Laravel http://lyften.com/projects/laravel-currency/