簡體   English   中英

Getter方法無法訪問自己的屬性

[英]Getter method cannot access its own property

我有以下具有屬性float $price實體模型。

當我創建這樣的getter方法時:

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

它一直給我以下錯誤:

未定義的屬性:App \\ Model \\ Entity \\ Model :: $ price

有什么問題?

您實際上是在嘗試從自身內部訪問getter方法。

為了使它起作用,請嘗試按以下方式重寫它:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM