1. 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

Discussion in 'Resolved Bug Reports' started by sonnb, Oct 12, 2013.

  1. sonnb

    sonnb Well-Known Member

    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.
     
    Adam Howard likes this.
  2. Mike

    Mike XenForo Developer Staff Member

    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).
     
    sonnb likes this.

Share This Page