简体   繁体   English

XAMPP和PHP 5.4.4的Normalizer致命错误

[英]Normalizer fatal error with XAMPP and PHP 5.4.4

When I use the PHP class Normalizer (eg \\Normalizer::normalize($string, Normalizer::FORM_KD); ) in my class Text.php in custom namespace Utils , I get the following error: 当我在自定义命名空间UtilsText.php中使用PHP类Normalizer (例如\\Normalizer::normalize($string, Normalizer::FORM_KD); )时,出现以下错误:

Fatal error: Class 'Utils\Normalizer' not found 
in C:\xampp\htdocs\MyProject\src\Utils\text.php on line 380

My project runs under XAMPP with PHP 5.4.4 . 我的项目在XAMPPPHP 5.4.4下运行。 I know also that: 我也知道:

  • Normalizer should work since PHP 5 >= 5.3.0 . PHP 5> = 5.3.0开始, Normalizer应该可以工作。
  • The extension php_intl.dll is enabled in my php.ini file. 我的php.ini文件中启用了扩展名php_intl.dll

What am I missing? 我想念什么?

You forgot the leading backslash In Normalizer::FORM_KD when calling \\Normalizer::normalize($string, Normalizer::FORM_KD) notice you only used one backslash in front of the class name, but not when you're using the class constant . 在调用\\Normalizer::normalize($string, Normalizer::FORM_KD)您在Normalizer::FORM_KD忘记了前导反斜杠 \\Normalizer::normalize($string, Normalizer::FORM_KD)注意,您仅在类名前面使用了一个反斜杠,但在使用类常量时却没有。

In PHP when you declare or import a namespace you are telling PHP to alias all of your function, class/interface, and constant names to your namespace. 在PHP中,当您声明或导入名称空间时,就是在告诉PHP将所有函数,类/接口和常量名称都别名为名称空间。

So the following code would issue a similar fatal error... 因此,以下代码将发出类似的致命错误...

<?php
namespace foo;

var_dump(DateTime::createFromFormat('Y-m-d','2012-12-06'));

The above code would issue an error of PHP Fatal error: Class 'foo\\DateTime' not found in /testfile.php on line 4 上面的代码将发出错误的PHP Fatal error: Class 'foo\\DateTime' not found in /testfile.php on line 4

To fix this make sure you always call those functions/classes/interfaces/constants which are not declared in your namespace/alias to the global namespace. 要解决此问题,请确保始终调用那些未在名称空间/别名中声明的函数/类/接口/常量给全局名称空间。

<?php
namespace foo;
/* Notice the leading backslash infront of DateTime*/
var_dump(\DateTime::createFromFormat('Y-m-d','2012-12-06'));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM