I've been using this exact same code for ages and never had any problems. Suddenly it stopped working.
I read about this problem on the internet and apparently you need to install PHP 5.3 or higher
, as well as install the PHP intl
plugin. I have both, but whenever I use the function below I still get a Fatal Error: Not found error for class 'NumberFormatter'
:
function format_item($value) { $format = new NumberFormatter('en_US', NumberFormatter::CURRENCY); return $format->formatCurrency($value, 'AUD'); }
Also, here is part of 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 added extension=php_intl.dll
in my php.ini
and it is also in my directory.
Why am I getting this error?
What you need is:
No need to change php.ini or do anything else. (Tested on Ubuntu 16.04 with PHP 7).
The most popular answer here is to have you uncomment a .dll file, which will never solve anything unless you are on a Windows server!
This seems to be a very strange problem, I solved it by:
I upgraded my PHP in Wamp throughthistutorial. I also updated the time zone settings in
php.ini
. When I upgraded it didn't work so I reverted back to the previous PHP version and the problem was solved.I have absolutely no idea why this solves the problem, but it works for me.