Re: HELP ! ! ! something simple . . . :D
- From: Tim Van Wassenhove <timvw@xxxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 31 Dec 2006 13:12:02 +0100
class A
{
public function methodA(){
//some useful code
}
class B
{
private A $instanceOfA; //but I am really not sure if this one's works
public __construct() {
$instanceOfA=new A();
}
public function methodB(){
$this->instanceOfA->methodA();
}
}
}
Anyway this is legal in terms of OO-Programming and also a well used
method for composing classes. I tried this out in PHP but it doesn't
seem to work. Obviously you'll have to create the instance within the
function/method you want to use it. Like:
What you really wanted to do in the constructor of B was the following:
public __construct() {
$this->instanceOfA = new A();
}
Because with $instanceOfA you create a local (in that function) variable...
--
Tim Van Wassenhove <url:http://www.timvw.be/>
.
- References:
- HELP ! ! ! something simple . . . :D
- From: CorfuVBProgrammer
- Re: HELP ! ! ! something simple . . . :D
- From: Kimmo Laine
- Re: HELP ! ! ! something simple . . . :D
- From: CorfuVBProgrammer
- Re: HELP ! ! ! something simple . . . :D
- From: CorfuVBProgrammer
- Re: HELP ! ! ! something simple . . . :D
- From: Yoursef
- Re: HELP ! ! ! something simple . . . :D
- From: CorfuVBProgrammer
- Re: HELP ! ! ! something simple . . . :D
- From: kostas1981
- HELP ! ! ! something simple . . . :D
- Prev by Date: Dynamic function creation?
- Next by Date: How to import large MySQL data dump using PHP?
- Previous by thread: Re: HELP ! ! ! something simple . . . :D
- Next by thread: Php in custom application
- Index(es):
Relevant Pages
|