Getter 方法无法访问它自己的 属性

Getter method cannot access its own property

我有以下实体模型 属性 float $price

当我创建这样一个 getter 方法时:

public function _getPrice()
{
    return $this->price*100;
}

它一直给我以下错误:

Undefined property: App\Model\Entity\Model::$price

有什么问题?

您实质上是在尝试从自身内部访问 getter 方法。

为了让它起作用,请尝试按如下方式重写它:

public function _getPrice()
{
    return $this->_properties['price'] * 100;
}