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:
Normalizershould work since PHP 5 >= 5.3.0.- The extension
php_intl.dllis enabled in myphp.ini
file.
What am I missing?
You forgot the leading backslash In
Normalizer::FORM_KDwhen 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…
The above code would issue an error of
PHP Fatal error: Class 'foo\DateTime' not found in /testfile.php on line 4To fix this make sure you always call those functions/classes/interfaces/constants which are not declared in your namespace/alias to the global namespace.