Fatal error: Class 'NumberFormatter' not found

Php

Php Problem Overview


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?

Php Solutions


Solution 1 - Php

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 - Php

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 - Php

This worked for me (Ubuntu 18.10, PHP 7.2.15)

sudo apt-get install php-intl
service apache2 restart

Solution 4 - Php

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

Solution 5 - Php

This means that your intl package for PHP is not installed and/or not enabled.

Step 1

Make sure that you install php7.2-intl (or check that it is installed). In my case, I had PHP 7.2, but the version could change.

To install, I used

sudo apt install php7.2-intl

Step 2

After a successful installation, go to php.ini and enable that extension by removing the comment, as follows

extension=intl

Step 3

Retstart apache

sudo service apache2 restart

Solution 6 - Php

I am running on ubuntu-16.04 and I am using php7, I had the same issue, It is because of the php_intl extension

the way I fixed it-

  • First check the extension is installed or not on your server, use below command to check it

     php -m | grep intl
    
  • If there's no results, you must need to install it

  • If not installed, let's install it

     sudo apt-get update
     sudo apt-get install php-intl
    
  • Finally you need to restart your web server after you install

https://stackoverflow.com/questions/33876590/class-numberformatter-not-found-error-in-simple-php-program

https://www.howtoinstall.co/en/ubuntu/xenial/php-intl

Solution 7 - Php

If you are using Google App Engine, just add:

extension = "intl.so"

to your application's php.ini file.

https://cloud.google.com/appengine/docs/php/runtime

Solution 8 - Php

Actually if you're using xampp and php > 7.*

edit the line ;extension=intl to extension=intl, restart mysql service and you're good to go.

Solution 9 - Php

for additional, if someone come here and on Laravel using php artisan serve and facing this problem, and already uncomment

extension=intl

on php.ini, don't forget to restart your Laravel dev server.

Solution 10 - Php

outdated

On Max OS X with PHP installed with the Homebrew, we can:

We can check is module intl installed:

$ php -m

We can check module info:

$ brew info php72-intl

And install it with:

$ brew install php72-intl

Solution 11 - Php

Add your PHP directory in the Path environment variable. (C:\Program Files\wamp\bin\php\phpX.XXX.XXX for wamp)

It has worked for me!

Solution 12 - Php

I got the same error from inside docker image php:7.4-fpm, so I added the following lines to the Dockerfile

RUN apt-get install -y libicu-dev # required dependency

RUN docker-php-ext install intl

Solution 13 - Php

This seems to be some really weird problem, and I somehow fixed it by doing the following:

I upgraded my PHP in Wamp through this tutorial. I also updated my timezone in php.ini When I upgraded it didn't work, so I reverted back to my previous version of PHP, and voilĂ  - it worked.

I have absolutely no idea how this solved the problem, however it worked for me.

Solution 14 - Php

Change in php extensions did not work for me so I updated my php version from php 5.6.25 to 7.0.10 and it worked

Solution 15 - Php

Solutions For ALL Windows and Mac.

Most of time this extension is not there, You just need to enable this extension in php.ini by uncommenting this line,

          extension=intl

if that line doesn't exists then add that line as like below in any place below first line,

         extension=intl
         extension=ext/php_intl.dll

for better result add below as like as well because with above one is in some scenario not working with only below one,

         extension=php_intl.dll

Then it look like this,

         extension=ext/php_intl.dll
         extension=php_intl.dll
         extension=intl

After That Mostly Don't Forgot to restart your server in my case I am using xampp otherwise the changes not working properly.

Solution 16 - Php

On CentOS 8:

sudo dnf install php-intl

Solution 17 - Php

the same problem happened to me, I already configured the php.ini and enabled the intl extension, the error persisted and I solved it by adding PHP in the environment variables of the system PATH in Windows

Solution 18 - Php

i could just do the following and it will work perfect.

$numbers = 123456789;

$toThousands = number_format($numbers);

results will be: 123,456,789, the func "number_format" is already build in function.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioncannatownView Question on Stackoverflow
Solution 1 - PhpChandzView Answer on Stackoverflow
Solution 2 - PhpNickView Answer on Stackoverflow
Solution 3 - PhpWonko the SaneView Answer on Stackoverflow
Solution 4 - PhpkeyaView Answer on Stackoverflow
Solution 5 - PhpGreesoView Answer on Stackoverflow
Solution 6 - Phpmizan3008View Answer on Stackoverflow
Solution 7 - PhpBen ShovalView Answer on Stackoverflow
Solution 8 - PhpErickView Answer on Stackoverflow
Solution 9 - PhpRio A.PView Answer on Stackoverflow
Solution 10 - PhpVladimir VukanacView Answer on Stackoverflow
Solution 11 - PhpquentView Answer on Stackoverflow
Solution 12 - PhpHany SakrView Answer on Stackoverflow
Solution 13 - PhpcannatownView Answer on Stackoverflow
Solution 14 - PhpsaadView Answer on Stackoverflow
Solution 15 - PhpmunazzilView Answer on Stackoverflow
Solution 16 - PhpMartin ZeitlerView Answer on Stackoverflow
Solution 17 - PhpNelson Partes VediaView Answer on Stackoverflow
Solution 18 - PhpCodedreamerView Answer on Stackoverflow