Page 1 of 1

Instance accessing classes functions

Posted: Mon Feb 26, 2007 7:07 pm
by jeffery
I have the following class structures

Code: Select all


// Module class
class Module extends Core
{

  // Some functions here which need to be accessed by the Setup class

}

// and then the Core class
Class Core 
{

  function __construct()
  {
    // Setup the Setup Class instance
    $this->set_setup();
  }


  function set_setup()
  {
	if (!isset($this->setup) && !is_object($this->setup))
	{
		require("core/setup/setup_html.php");
		$this->setup = new Setup_HTML();
	}
  }

}


Now my question is how do I make available the Module classes functions to the Setup_HTML class? Is it just a matter of passing the Modules object to the setup class upon instantiation or is there a neater approach ?

Jeffery

Posted: Mon Feb 26, 2007 7:45 pm
by Christopher
You can just do:

Code: Select all

$this->setup = new Setup_HTML($this);
But I does not seem like a good idea to create spaghetti dependencies like that. I get the sense that the Setup_HTML class is the View and the Module may be the Model. If so then:

Code: Select all

$setup = new Setup_HTML(new Module());