Posted by kostas1981 on 12/31/06 01:36
CorfuVBProgrammer schrieb:
> This way it works but only into the constructor method.
>
> I have try to use ot in other methods in the class and doesn't work ! !
> ! ? ? ?
>
> Is any other way ? ? ?
Hello!
I'm a PHP newbie, but I've been busy writing much OO-Code over the last
years.
I had an idea solving this problem using the following scheme:
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:
class B
{
//....
public function methodB(){
$instanceOfA=new A();
$instanceOfA->methodA();
}
}
Well I ran a test with that and it worked. It's not that elegant but I
think it makes sense...
regards
Kostas
[Back to original message]
|