Instance accessing classes functions

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
jeffery
Forum Contributor
Posts: 105
Joined: Mon Apr 03, 2006 3:13 am
Location: Melbourne, Australia
Contact:

Instance accessing classes functions

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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());
(#10850)
Post Reply