I have such a class hierarchy
class Question extends yii\db\ActiveRecord {/** Implementation **/} class TextQuestion extends Question {/** Implementation **/} class SumQuestion extends Question {/** Implementation **/}
Is it possible to convert a Question
object to TextQuestion
or SumQuestion
?
Primitive example
$question = new Question(); $sum = (SumQuestion)$question;
The first idea that came to mind is to transfer attributes, but perhaps there is a better solution.
$question = new Question(); $sum = new SumQuestion(); $sum->setAttributes($question->getAttributes());
Thanks in advance for your help!