Value formatter can return int type when requested a float

Kruzya

Well-known member
Affected version
2.2.9
PHP:
$input = 999.00;
$type = \XF\Mvc\Entity\Entity::FLOAT;

$output = \XF::em()->getValueFormatter()->castValueToType($input, $type, []);

var_dump($input); // float(999)
var_dump($output); // int(999)

This is not big problem, if we're not working with entities:
PHP:
$item = \XF::em()->create('Something:Item'); // cost_amount - FLOAT, cost_currency - STR
$item->cost_amount = 999.00;
$item->cost_currency = 'RUR';
$item->save();

if ($item->isChanged('cost_amount') || $item->isChanged('cost_currency'))
{
    die('Amount or currency is changed!!!'); // not will be called, because entity already saved.
}

$item->cost_amount = 999.00;
$item->cost_currency = 'RUR';
if ($item->isChanged('cost_currency'))
{
    die('Currency is changed!!!'); // not called...
}

if ($item->isChanged('cost_amount'))
{
    die('Amount is changed!!!'); // this will be called, but don't should be, because the real value is the same
}
 
Top Bottom