Reply to Re: HELP ! ! ! something simple . . . :D

Your name:

Reply:


Posted by Tim Van Wassenhove on 12/31/06 12:12

> 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/>

[Back to original 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

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