Help - Search - Members - Calendar
Full Version: [PHP] Class help
Invision Power Services > Community Forums > Community Web Design and Coding
bılʞ
I have two classes.

CODE
class foo
{
    function foo()
    {
       $this->bar = 'barbarbar';
    }
}



CODE
  class bar
  {
     function bar()
     {
        $this->foo = 'foofoofoo';
     }
  }


"foo" is my main class, and I want to initialize it first:

CODE
$foo = new foo;


but I also want "bar"'s methods and properties to be available under $foo, how can I do this?

E.G.

CODE
$foo->bar();

echo $foo->foo;


as well as:

CODE
$foo->foo();
  
  echo $foo->bar;


I should also make it clear that I don't want to have to do $foo->bar = new bar; and have to access "bar"'s methods and properties that way.
Barn
Change

CODE
class foo
{
// ...
}


to

CODE
class foo extends bar
{
// ...
}
bılʞ
QUOTE(Barn @ Jul 18 2005, 01:29 AM) *
Change

CODE
class foo
{
// ...
}


to

CODE
class foo extends bar
{
// ...
}


I was thinking about that just now funnily enough, lol. Wouldn't I have to initialize bar first tho?
Barn
You'd have to define it first. Don't think you'd have to initialize it though.
bılʞ
QUOTE(Barn @ Jul 18 2005, 01:33 AM) *
You'd have to define it first. Don't think you'd have to initialize it though.


So as soon as I initialize foo bar is automatically initialized? Cool. Thanks. thumbsup.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.