Fatal error: Class 'NumberFormatter' not found

I've been using this exact same code for ages, and I have never had a single problem. Now all of a sudden it has stopped working.

I have read across the internet about this problem, and apparently you need PHP 5.3 or higher installed, and the PHP intl plugin installed. I have both of these, yet I am still receiving a Fatal error: Class 'NumberFormatter' not found error whenever I use the following function:

function format_item($value)
{
       $format = new \NumberFormatter('en_US', \NumberFormatter::CURRENCY);
       return $format->formatCurrency($value, 'AUD');
}

Also, here is a snippit from my php.ini file showing that I have the PHP intl plugin installed:

[intl]
intl.default_locale = fr_FR
; This directive allows you to produce PHP errors when some error
; happens within intl functions. The value is the level of the error produced.
; Default is 0, which does not produce any errors.
intl.error_level = E_WARNING

I also have the extension=php_intl.dll in my php.ini, and it is also in my directory.

Why am I getting this error?


Solution 1:

You just need to enable this extension in php.ini by uncommenting this line:

extension=ext/php_intl.dll

For more details visit, Enable intl extension

Solution 2:

All you need is:

apt-get install php7.0-intl

No need to change php.ini or do anything else. (Tested on PHP 7 on Ubuntu 16.04).

The most up-voted answer here has you uncommenting a .dll which will never solve anything unless you are on a Windows server!

Solution 3:

This worked for me (Ubuntu 18.10, PHP 7.2.15)

sudo apt-get install php-intl
service apache2 restart

Solution 4:

I am using PHP 5.5 version and got the same error in Ubuntu Machine. I have installed php5-Intl package and restarted my apache server. This resolved the issue.

For PHP5

sudo apt-get install php5-intl

For PHP7

sudo apt-get install php7.0-intl

For Mac OS X, use the following command for PHP5.6

brew install php56-intl

For different OS, checkout this page : http://php.net/manual/en/intl.installation.php

To check successful installation, run the command php -m. This should show the intl package in the list.

If you are using XAMPP in Mac OS X, php-intl will sometimes create different problems. You can follow the debug steps mentioned here

If you are facing Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20121212/intl.so' error, follow the steps as mentioned here