Skip to content

Getter methods shouldn't change values #1133

Closed
@mzeis

Description

@mzeis

Magento 2 sometimes changes values in getter methods. This can lead to undesirable side effects.

An example from the product model:

/**
 * Get product status
 *
 * @return int
 */
public function getStatus()
{
    if ($this->_getData(self::STATUS) === null) {
        $this->setData(self::STATUS, \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED);
    }
    return $this->_getData(self::STATUS);
}

I'm aware this is a very general issue and has to be tackled over time during the whole code refactoring process but it is important.

Metadata

Metadata

Assignees

Labels

Issue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentbug report

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions