/** * @param string|Buffer $compareTo * @return bool */ public function equals($compareTo) { if ($compareTo instanceof Buffer) { // cheap checks if ($this->getTextLength() != $compareTo->getTextLength()) { return false; } if ($this->getLength() != $compareTo->getLength()) { return false; } // full check $current_value = $this->toValue(); $value = $compareTo->toValue(); if (!is_array($current_value) && !is_array($value)) { return $current_value === $value; } elseif (is_array($current_value) && is_array($value)) { for ($i = 0; $i < count($current_value); $i++) { if ($current_value[$i] !== $value[$i]) { return false; } } return true; } return false; } else { return $this->strLength == $this->length && $this->strLength == strlen($compareTo) && $this->__toString() === $compareTo; } }