2013-03-07 62 views
1

我的主機更新php版本從5.2到5.3(不能回到5.2版本) 我在我的網站只有一個警告錯誤,這是: - >編輯從php 5.2到php 5.3版本的錯誤

Warning: number_format() expects parameter 2 to be long, string given in /currency.php on line 77 

這裏是文件的代碼:

<?php 
defined('_JEXEC') or die('Restricted access'); 
class GCurrency 
{ 
var $_symbol=null; 
var $_value=null; 
var $_currency=null; 
var $_decimal_separator=null; 
var $_decimals=null; 
var $_val_separator=null; 
var $_format=null; 
function __construct($val=0,$symbol='$',$currency='USD',$format="%S %V %C",$decimal="2",$dec=".",$v=",") 
{ 
    $this->_symbol=empty($symbol)?'$':$symbol; 
    $this->_currency=empty($currency)?"USD":$currency; 
    $this->_value=$val; 
    $this->_decimal_separator=empty($dec)?".":$dec; 
    $this->_decimals=empty($decimal)?"2":$decimal; 
    $this->_val_separator=empty($val)?",":$v; 
    $this->_format=empty($format)?"%S %V %C":$format; 
} 
function setCurrencySymbol($symbol='$') 
{ 
    $this->_symbol=$symbol; 
} 
function setDecimals($dec="2") 
{ 
    $this->_decimals=$dec; 
} 
function setCurrency($currency="USD") 
{ 
    $this->_currency=$currency; 
} 
function setValue($val=0,$symbol='$',$currency='USD') 
{ 
    $this->_symbol=empty($symbol)?'$':$symbol; 
    $this->_currency=empty($currency)?"USD":$currency; 
    $this->_value=$val; 
} 
function setDecimalSeparator($dec=".") 
{ 
    $this->_decimal_separator=$dec; 
} 
function setValueSeparator($val=",") 
{ 
    $this->_val_separator=$val; 
} 
function setFormat($format="%S %V %C") 
{ 
    $this->_format=$format; 
} 
function set($val=0,$symbol='$',$currency='USD',$format="%S %V %C",$decimal="2",$dec=".",$v=",") 
{ 
    $this->_symbol=empty($symbol)?'$':$symbol; 
    $this->_currency=empty($currency)?"USD":$currency; 
    $this->_value=$val; 
    $this->_decimal_separator=empty($dec)?".":$dec; 
    $this->_decimals=empty($decimal)?"2":$decimal; 
    $this->_val_separator=empty($val)?",":$v; 
    $this->_format=empty($format)?"%S %V %C":$format; 
} 
function setParameters($format="%S %V %C",$decimal="2",$dec=".",$v=",") 
{ 
    $this->_decimal_separator=empty($dec)?".":$dec; 
    $this->_decimals=empty($decimal)?"2":$decimal; 
    $this->_val_separator=empty($val)?",":$v; 
    $this->_format=empty($format)?"%S %V %C":$format; 
} 
function toString() 
{ 
    $pattern=array(); 
    $pattern[]='/%S/i'; 
    $pattern[]='/%V/i'; 
    $pattern[]='/%C/i'; 
    $value=array(); 
    /*$value[]=$this->_symbol;*/ 
    $value[]=number_format($this->_value,$this->_decimals,$this->_decimal_separator,$this->_val_separator); 
    $value[]=$this->_currency;  
    return preg_replace($pattern,$value,$this->_format); 
} 
} 
?> 

有人可以請給我一個想法,這可怎麼固定的嗎?

+0

錯誤消息似乎很明顯。不要將字符串傳遞給'number_format',傳遞一個數字。 – 2013-03-07 18:06:58

回答

0

由於錯誤說,它預計長。我懷疑PHP正在轉換爲長,但是在所有三元語句中,您將$ this_decimals設置爲一個字符串,請注意您將包裝值的雙引號。例如,「2」。

+0

非常感謝您的幫助,我修復了鏈接「Schleis」寫道的問題。謝謝 – 2013-03-07 18:13:04