【问题标题】:Symfony - directly access the class properties [duplicate]Symfony - 直接访问类属性[重复]
【发布时间】:2021-07-04 11:15:54
【问题描述】:

我在实体类中创建了小方法,我可以在其中更改两个字段中的一些内容:

这是我的水果实体方法:

 /**+
 * @return $this
 */
public function freeBasket(): Fruit
{
    $this->setFreshBasketName($this->getBasketName());
    $this->seBasketName(null);
    return $this;
}

但我有一个想法,因为这是在 Fruit 类中,所以不需要为它使用方法,有一种方法可以直接访问类属性,而不是删除 setFreshBasketName() 方法。

我怎样才能做到这一点? Symfony 的新功能。 :)

【问题讨论】:

  • 与 Symfony 或 Doctrine 无关。这是基本的 PHP 知识和property access

标签: php


【解决方案1】:

你可以试试

public function freeBasket(): Fruit
{
    $this->freshBasketName = $this->getBasketName();
    $this->basketName = null;
    return $this;
}

【讨论】:

    猜你喜欢
    • 2020-02-13
    • 1970-01-01
    • 2013-06-12
    • 1970-01-01
    • 1970-01-01
    • 2014-10-11
    • 2014-02-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多