Yii::$app->formatter->AsCurrency changes ?

I saw a weird thing with Yii2 formatter AsCurrency and wonder what have changed.




// PHP 5.5.9-1ubuntu4.20 running yii2 2.0.9


// in main.php

'formatter' => [

    'currencyCode' => '$'

]


//work

echo \Yii::$app->formatter->asCurrency(100); // prints out $ 100


// in main.php

'formatter' => [

    'currencyCode' => 'USD'

]


echo \Yii::$app->formatter->asCurrency(100); // prints out USD 100






// PHP 5.6.14-1+deb.sury.org~trusty+1 running yii2 2.0.9


// in main.php

'formatter' => [

    'currencyCode' => '$' // this give error, must set to 'USD'

]


//ERROR: yii\i18n\Formatter:AsCurrency(100)

//Invalid Parameter – yii\base\InvalidParamException

//Formatting currency value failed: 1 Number formatting failed: U_ILLEGAL_ARGUMENT_ERROR


// to fix this error I have to set 'currencyCode' => 'USD'

\Yii::$app->formatter->asCurrency(100); // prints out $ 100




Is this PHP or Yii issue ?

As far as I can see, 2nd case is correct. I guess the difference is caused by lack of intl or ICU data installed on one of the servers.

You are correct. The first server didnt have intl extension installed. After installing the intl extension, both servers act same with proper ICU code.

Thanks so much