致命錯誤:找不到類別'NumberFormatter'
P粉817354783
2023-08-16 16:29:06
<p>我已經使用這段完全相同的程式碼很久了,從來沒有出過任何問題。突然間它停止工作了。 </p>
<p>我在網路上閱讀了關於這個問題的資料,顯然你需要安裝<code>PHP 5.3或更高版本</code>,以及安裝<code>PHP intl</code>外掛程式。我兩者都有,但是每當我使用下面的函數時,我仍然收到一個<code>致命錯誤:找不到類別'NumberFormatter'</code>的錯誤:</p>
<pre class="brush:php;toolbar:false;">function format_item($value)
{
$format = new NumberFormatter('en_US', NumberFormatter::CURRENCY);
return $format->formatCurrency($value, 'AUD');
}</pre>
<p>此外,這是我<code>php.ini</code>檔案的一部分,顯示我已經安裝了<code>PHP intl</code>外掛程式:</p>
<pre class="brush:php;toolbar:false;">[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</pre>
<p>我還在我的<code>php.ini</code>中加入了<code>extension=php_intl.dll</code>,而且它也在我的目錄中。 </p>
<p>為什麼我會收到這個錯誤? </p>
你所需要的是:
無需更改php.ini或進行其他操作。 (在Ubuntu 16.04上測試過PHP 7)。
這裡最受歡迎的答案是讓你取消註解一個.dll文件,除非你在Windows伺服器上,否則這永遠不會解決任何問題!
這似乎是一個非常奇怪的問題,我透過以下方式解決了它:
我透過這個教學升級了我的Wamp中的PHP。我還更新了
php.ini
中的時區設定。當我升級後,它沒有起作用,所以我恢復回了之前的PHP版本,然後問題解決了。我完全不知道這樣做為什麼能解決問題,但對我來說有效。