开发者

Calling overridden method from within overriding method in OO PHP

Working in a symfony model, I want to override a function and call the overridden function from within the overriding one, along the lines of

class MyClass extends BaseMyClass {

  function setMyProperty($p) {
    parent::setMyProperty($p);
    //do some other stuff
  }

}

This is resulting in a segmentation fault. I don't want to alter the parent class - it's been 开发者_StackOverflow中文版generated by symfony, and may feasibly be overwritten in the future if the model is rebuilt. This seems like something that should be straightforward, but I'm struggling to find the solution.


Since you saw the problem, I guess you should mark it as answered to remove it from the unanswered list.


I've managed to find a solution to my own question on the symfony project forum.

I can't call the overridden function because it doesn't exist. Though it exists enough for me to override it.

Using

$this->_set('my_property', $p);

Works where

parent::setMyProperty($p);

Causes the error.

Note that

$this->setMyProperty($p);

Works fine in my class if the method has not been overridden.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜