active-record icon indicating copy to clipboard operation
active-record copied to clipboard

The parameter identical of the method isAttributeChanged in class BaseActiveRecord has no effect when its value is false.

Open niqingyang opened this issue 4 months ago • 2 comments

What steps will reproduce the problem?

The parameter identical of the method isAttributeChanged in class BaseActiveRecord has no effect when its value is false.

/**
  * Returns a value indicating whether the named attribute has been changed.
  *
  * @param string $name The name of the attribute.
  * @param bool $identical Whether the comparison of new and old value is made for identical values using `===`,
  * defaults to `true`. Otherwise `==` is used for comparison.
  *
  * @return bool Whether the attribute has been changed.
  */
public function isAttributeChanged(string $name, bool $identical = true): bool
{
    if (isset($this->attributes[$name], $this->oldAttributes[$name])) {
        if ($identical) {
            return $this->attributes[$name] !== $this->oldAttributes[$name];
        }

        return $this->attributes[$name] !== $this->oldAttributes[$name]; // !== in this line of code should be replaced with !=
    }

    return isset($this->attributes[$name]) || isset($this->oldAttributes[$name]);
}

What is the expected result?

The method implementation is consistent with the description, use == for comparison when the parameter identical is false

What do you get instead?

Method implementation is inconsistent with description

Additional info

Q A
Version 1.0.?
PHP version 8.2
Operating system MacOS

niqingyang avatar Feb 15 '24 17:02 niqingyang