src/SimpleDOM.php
public function setAttribute($strName, $strValue)
    {
        if (!isset($this->attributes()->$strName)) {
            $this->addAttribute($strName, $strValue);
            return $strName;
        } else {
            $this->attributes()->$strName = $strValue;
            return $this->attributes()->$strName;
        }
    }
public function setAttribute($strName, $strValue)
    {
        if (!isset($this->attributes()->$strName)) {
            $this->addAttribute($strName, $strValue);
            return $strName;
        } else {
            $this->attributes()->$strName = $strValue;
            return $this->attributes()->$strName;
        }
    }
Set (or create) Attribute

@param string $strName
@param string $strValue
@return string