Cast the current object ($this) to a descendent class
问题 I have a class where it may be necessary to change the object to a descendent class further down the line. Is this possible? I know that one option is to return a copy of it but using the child class instead, but it\'d be nice to actually modify the current object... so: class myClass { protected $var; function myMethod() { // function which changes the class of this object recast(myChildClass); } } class myChildClass extends myClass { } $obj = new myClass(); $obj->myMethod(); get_class_name(