覆盖doctrine魔术访问器方法

时间:2010-12-15 17:40:49

标签: php symfony1 doctrine

我尝试覆盖属性getter方法(由sfDoctrineRecord :: __ call()方法处理),如下所示:

//myClass.class.php
public function getProperty()
{
  $property = parent::getProperty();
  //the following line is never reached
  return $property;
}

但这导致无限递归。它有可能吗?如何?

2 个答案:

答案 0 :(得分:8)

试试这样:

public function getProperty()
{
  $property = $this->_get('property');
  //the following line is never reached
  return $property;
}

另外,请阅读有关自定义变更器和访问器的信息。

答案 1 :(得分:0)

DoctrineRecord.__call方法中,您会看到它使用call_user_func_array,它会尝试调用该类的getProperty方法。

由于你已经覆盖了getProperty,它正在调用子类定义,所以它正在调用它自己。

相关问题