Php 如何在Symfony中使用“IntlDateFormatter”?
如何在Symfony 4.4中实现Php 如何在Symfony中使用“IntlDateFormatter”?,php,symfony,symfony-4.4,Php,Symfony,Symfony 4.4,如何在Symfony 4.4中实现IntlDateFormatter 关于,我已经安装了symfony/intl 现在,当我在代码中使用它时: use Symfony\Component\Intl\DateFormatter\IntlDateFormatter; $formatter = new IntlDateFormatter( "de-DE", IntlDateFormatter::FULL, IntlDateF
IntlDateFormatter
关于,我已经安装了symfony/intl
现在,当我在代码中使用它时:
use Symfony\Component\Intl\DateFormatter\IntlDateFormatter;
$formatter = new IntlDateFormatter(
"de-DE",
IntlDateFormatter::FULL,
IntlDateFormatter::NONE,
"Europe/Berlin",
IntlDateFormatter::GREGORIAN,
"MMMM YYYY"
);
我得到无法实例化抽象类Symfony\Component\Intl\DateFormatter\IntlDateFormatter
。我知道抽象类不能被实例化。但我不确定如何实施。来自:
Composer会自动在全局命名空间中公开这些类
如果我们检查源代码,这更容易理解。在DateFormatter/IntlDateFormatter.php
中定义的类被标记为抽象类,但在Resources/stubs/IntlDateFormatter.php
中有一个实现如下所示:
use Symfony\Component\Intl\DateFormatter\IntlDateFormatter as BaseIntlDateFormatter;
/**
* Stub implementation for the IntlDateFormatter class of the intl extension.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @see BaseIntlDateFormatter
*/
class IntlDateFormatter extends BaseIntlDateFormatter
{
}
如果没有安装扩展,自动加载将自动加载Symfony的实现
$fmt = new \IntlDateFormatter(...);
^