moneyphp / money

PHP implementation of Fowler's Money pattern.
http://moneyphp.org
MIT License
4.63k stars 441 forks source link

PHP Fatal error: Uncaught Error: Class 'NumberFormatter' not found #564

Closed gadget00 closed 5 years ago

gadget00 commented 5 years ago

On my webserver using PHP 7.2-19, I can't manage to run my code because I keep getting the error of an unrecognized 'NumberFormatter' class. I removed a reinstalled with composer a few times, and tested another formatters like the DecimalMoneyFormatter and because it doesn't require an instance of NumberFormatter, that one works Ok.

However, locally in my laptop using PHP 5.6.36 the NumberFormatterclass is detected correctly and the IntlMoneyFormatterworks flawlessly.

What can I check or consider, in order to fix this issue? I dont want to downgrade my whole webserver installation due to this; it must be some detail I am missing out I guess.

Please help; thanks

UlrichEckhardt commented 5 years ago

First step: Extract the steps necessary to reproduce the issue in isolation and add that to your question here. Keep in mind that nobody here knows what code is running on your machine. Then, also read the release notes with changes between the two PHP versions. Further, what versions of moneyphp/money are we talking about?

kslimani commented 5 years ago

@gadget00 the issue you describe sound like you are missing the php7.2-intl extension package.

gadget00 commented 5 years ago

Thanks for the orientation; Im using the 3.2 version, that was downloaded through composer.

I'm using a simple variation of the same example code that is shown in the documentation:

use Money\Currencies\ISOCurrencies;
use Money\Currency;
use Money\Formatter\IntlMoneyFormatter;
use Money\Money;

$money = new Money(100, new Currency('PAB'));
$currencies = new ISOCurrencies();

//THIS LINE is what throws the error
$numberFormatter = new \NumberFormatter('es_PA', \NumberFormatter::CURRENCY); 

$moneyFormatter = new IntlMoneyFormatter($numberFormatter, $currencies);

$total_cash = $moneyFormatter->format($money);

I had no idea about changes between the two PHP versions. At least that is not pointed out in the official documentation. I'll go and seek that additional documentation

gadget00 commented 5 years ago

@gadget00 the issue you describe sound like you are missing the php7.2-intl extension package.

thats great; how do I install it?

I saw it was a "suggestion" by composer but didnt knew how to add it

gadget00 commented 5 years ago

@gadget00 the issue you describe sound like you are missing the php7.2-intl extension package.

thats great; how do I install it?

I saw it was a "suggestion" by composer but didnt knew how to add it

Oh, I just saw is a PHP additional module. I´ll use my package manager to install it then. Have to say, the documentation wasn't clear enough about the "intlextension" been a PHP additional package, and not a PHP composer library .

I will test it and confirm; thank you

kslimani commented 5 years ago

@gadget00 on linux Debian or Ubuntu, it should be something like apt-get install php7.2-intl

gadget00 commented 5 years ago

I can confirm that my PHP 7.2-19 installation was missing thephp7.2-intl extension, and that was the cause of the problem. I installed it through my linux package manager, restarted the apache service and now it is working fine.

I'll proceed to close this issue. Great work!

sagikazarmark commented 5 years ago

I just want to say: it's absolutely amazing to see the community helping out on an issue tracker! Kudos to everyone!

spotstat commented 3 years ago

@gadget00 on linux Debian or Ubuntu, it should be something like apt-get install php7.2-intl

I can verify that this solved the issue for me ("apt-install php7.4-intl", in my case)