drkstr Posted September 5, 2006 Share Posted September 5, 2006 Hello,I need to be able to extend an object, but all the inherited data in the child object must allread be instantiated. What are the best methods/practices to do this? The reason why I ask, is I am unable to use a constructor in the child. The child object needs to be formed in such a way that it can be made "callable" by client side Flash code. Constructors will break this functionality, but it will call an init() method if it exists.Can any one recommend the best way to get the data in the child object instantiated? If I just call the parent constructor from a method in a child object, will the inherited data in the child object be instantiated as well? Should I just get rid of the parent constructor and put it in the init() function of the child? I would prefer not to do the later since the constructor of the parent uses some private helper functions that I would have to make public.Thanks for your time!...drkstr Quote Link to comment Share on other sites More sharing options...
Jenk Posted September 5, 2006 Share Posted September 5, 2006 What's stopping you using the constructor?![code]<?phpclass Foo{ protected $bar; public function __construct () { $this->bar = 'foobar'; }}?>[/code] Quote Link to comment Share on other sites More sharing options...
drkstr Posted September 5, 2006 Author Share Posted September 5, 2006 Like I said, using a constructor in the child object breaks the Flash remoting (amfphp). I'm not sure why, but it does. right now I am just adding a data member to the child object called myObjectVars, then in the init() method, I'm doing crating an instance of the parent:[code]class ServiceNetworkConfig extends NetworkConfig { private $myObjectVars = array(); public function init() { $netConfig = new NetworkConfig(); $this->myObjectVars = get_object_vars($netConfig); } #This function will be callable by the client side Flash script. public function retrieveData() { return $this->myObjectVars; }}[/code]I don't like this though because it makes parsing the data back to the parent class difficult.Thanks for the reply!...drkstr 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.