• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Fixed False comparison in DataWriter _setInternal

sonnb

Well-known member
#1
PHP:
protected function _setInternal($table, $field, $newValue, $forceSet = false)
    {
        $existingValue = $this->get($field, $table);
        if ($forceSet
            || $existingValue === null
            || !is_scalar($newValue)
            || !is_scalar($existingValue)
            || strval($newValue) != strval($existingValue)
        )
        {
            if ($newValue === $this->getExisting($field, $table))
            {
                unset($this->_newData[$table][$field]);
            }
            else
            {
                $this->_newData[$table][$field] = $newValue;
            }
        }
    }
XenForo use this function to check if new value is equal to existing value and save the new value. But this might be false in some case because of
PHP:
strval($newValue) != strval($existingValue)
For example
PHP:
strval('0122456') != strval('122456')
will return false (mean they are equal) while they are not. It should be
PHP:
strval($newValue) !== strval($existingValue)
for correct result.
 

Mike

XenForo developer
Staff member
#2
Much is said about PHP's type juggling with comparisons though I think this is one of the few times I've been caught out by this particular insane behavior (though I suspect there may be other places where it hasn't been noticed).