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