dran0703 2012-12-06 10:28
浏览 93
已采纳

使用XAMPP和PHP 5.4.4的Normalizer致命错误

When I use the PHP class Normalizer (e.g. \Normalizer::normalize($string, Normalizer::FORM_KD);) in my class Text.php in custom namespace Utils, I get the following error:

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. I know also that:

  • Normalizer should work since PHP 5 >= 5.3.0.
  • The extension php_intl.dll is enabled in my php.ini file.

What am I missing?

  • 写回答

1条回答 默认 最新

  • douzhi2760 2012-12-06 10:47
    关注

    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.

    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.

    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

    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'));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?