echochamber Posted September 1, 2013 Share Posted September 1, 2013 I was wondering if this could be done using the __clone magic method or something similar. Quote Link to comment https://forums.phpfreaks.com/topic/281755-instantiate-a-child-class-object-as-a-copy-of-an-already-instantiated-parent-class-object/ Share on other sites More sharing options...
kicken Posted September 1, 2013 Share Posted September 1, 2013 Your going to need to be a bit more specific on what you want to do. __clone and the clone keyword are for creating duplicates of an object, but both are still the same class. If you want a difference class you'd need to write your own method to achieve that. Quote Link to comment https://forums.phpfreaks.com/topic/281755-instantiate-a-child-class-object-as-a-copy-of-an-already-instantiated-parent-class-object/#findComment-1447675 Share on other sites More sharing options...
echochamber Posted September 1, 2013 Author Share Posted September 1, 2013 Your going to need to be a bit more specific on what you want to do. __clone and the clone keyword are for creating duplicates of an object, but both are still the same class. If you want a difference class you'd need to write your own method to achieve that. Ok, that answered my question. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/281755-instantiate-a-child-class-object-as-a-copy-of-an-already-instantiated-parent-class-object/#findComment-1447685 Share on other sites More sharing options...
tobimichigan Posted September 1, 2013 Share Posted September 1, 2013 Now why in world would you want to "instantiate a child class object" as " a copy of an instantiated parent class object", ? Isn't that clumsy ? or repeatitive? Quote Link to comment https://forums.phpfreaks.com/topic/281755-instantiate-a-child-class-object-as-a-copy-of-an-already-instantiated-parent-class-object/#findComment-1447711 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.