Reply to Re: include file in class

Your name:

Reply:


Posted by Janwillem Borleffs on 01/04/06 02:41

Carramba wrote:
> but it doesn't make eny sence to include it over and over again in
> every function so I would like to that get some thing like
>
>
> PHP Code:
> class myClass{
> include 'func.php'; //but this don't work
> func(); // $var=3
>

That's where you can use the constructor for:

class myClass {
var $var;

function myClass() {
include 'include.php';
$this->var = getVar();
}
}

However, keep in mind that this is not a very good OO design. If you have a
collection of utility functions, the best way to use them is through
static/instantiated method calls or through inheritance:

Example A (static calls):

include 'Utils.php';

class myClass {
var $var;

function myClass() {
$this->var = Utils::getVar();
}
}


Example B (inheritance):

include 'Utils.php';

class myClass extends Utils {
var $var;

function myClass() {
$this->var = $this->getVar();
}
}


JW

[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

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