You are here: Re: HELP ! ! ! something simple . . . :D « PHP Programming Language « IT news, forums, messages
Re: HELP ! ! ! something simple . . . :D

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация