mbeals Posted July 28, 2008 Share Posted July 28, 2008 Is it possible to change the class of an object if it retains the same parent? IE <?php class device { Quote Link to comment Share on other sites More sharing options...
obsidian Posted July 28, 2008 Share Posted July 28, 2008 Is it possible to change the class of an object if it retains the same parent? IE <?php class device { Can you be more specific? Changing a class name in the definition of an object is simple enough, but it will break all the code that is instantiating the object by its previous name. Why would you want to change the class name of an object? Quote Link to comment Share on other sites More sharing options...
mbeals Posted July 28, 2008 Author Share Posted July 28, 2008 sorry, I was attempting to tab over while writing code (which doesn't work in this box) and submitted the topic before it was complete. I was going to ask if you have an object which is a child of another (or even of an abstract), is it possible to change the child objects class, retaining the abstracted attributes. Effectively taking an object of one class, destroying it, then creating a new instance of another class (with the same parent) and persisting the common attributes. ie: <?php class parent{ protected $id; protected $info; function changeClass($newClass){ } } class child1 extends parent{ function __construct(){ } } class child2 extends parent{ } $test = new child1; $test->changeClass('child2'); ?> where any attributes defined through child one that are common with child2 would persisit. Could I just do something like: <?php function ChangeClass($newClass){ unset($this); return new($newClass); } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.