Jump to content

Archived

This topic is now archived and is closed to further replies.

drkstr

best way to inherit an instantiated object?

Recommended Posts

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

Share this post


Link to post
Share on other sites
What's stopping you using the constructor?!

[code]<?php

class Foo
{
    protected $bar;

    public function __construct ()
    {
        $this->bar = 'foobar';
    }
}
?>[/code]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.