简体   繁体   English

替代学说魔术访问器方法

[英]Override doctrine magic accessor method

I try to override a property getter method (which is processed by sfDoctrineRecord::__call() method) like this: 我试着像这样重写属性getter方法(由sfDoctrineRecord :: __ call()方法处理):

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

But this results in infinite recursion. 但这导致无限递归。 Is it possible and how? 有可能吗?

Try like this: 尝试这样:

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

Also, read about custom mutators and accessors. 另外,请阅读有关自定义更改器和访问器的信息。

Within the DoctrineRecord.__call method you'll see it uses call_user_func_array , which will try to call the getProperty method of the class. DoctrineRecord .__ call方法中,您将看到它使用call_user_func_array ,它将尝试调用该类的getProperty方法。

Since you've overriden getProperty , it's calling the child class definition, so it's calling itself. 由于您已覆盖getProperty ,因此它正在调用子类定义,因此它本身也在调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM