Calling an overridden method from an overriding method in OO PHP

Working in the symfony model, I want to override a function and call an overridden function from within the main one, line by line

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

This results in a segmentation error. I do not want to change the parent class - it was generated by symfony and may be overwritten in the future if the model is restored. It seems like it should be simple, but I'm trying my best to find a solution.

+4
source share
2 answers

I managed to find a solution to my own question in the Symfony forum.

I cannot call an overridden function because it does not exist. Although for me it is enough to redefine it.

Using

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

Works where

 parent::setMyProperty($p); 

Causes an error.

note that

 $this->setMyProperty($p); 

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

-2
source

Since you saw the problem, I think you should mark it as an answer in order to remove it from the unanswered list.

0
source

Source: https://habr.com/ru/post/1306467/


All Articles