Alexandru Vlas
Alexandru Vlas

Reputation: 1415

Edit an error from php 5.2 to php 5.3 version

My host updated the php version from 5.2 to 5.3 (can't go back to 5.2 version) and I have only one warning error in my site, which is this: ->

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

Here is the code of the file:

<?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);
}
}
?>

Can somebody PLEASE give me an idea how this can be fixed PLEASE?

Upvotes: 1

Views: 315

Answers (2)

Chris
Chris

Reputation: 943

As the error says, it expects long. I suspect PHP is converting to long anyway, however in all your ternary statements you are setting $this_decimals to a string, note the double quotes you are wrapping the value in.. "2" for example.

Upvotes: 0

Schleis
Schleis

Reputation: 43700

Make $this->_decimals a number rather than a string. So cast it to an integer and the warning will go away.

http://php.net/manual/en/function.number-format.php

Upvotes: 1

Related Questions