Answer the question
In order to leave comments, you need to log in
How to call child class in parent method?
Hello.
There is this code:
echo (new Select->setAttr('name', 'list'))->add( (new Option())->setText('item1') )->show()
I don't know how to call the child class Option in the add method as described above.
Answer the question
In order to leave comments, you need to log in
Most likely you don't mean "call the class" but accept it.
I will assume that Option::setText() returns void, and Select::add() takes Select(Option).
You either need to return a reference to the instance in setText() (return $this) or place the text initialization in the Option class constructor and accept it in $select->add(new Option('text')).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question