Afficher un message
Vieux 17/09/2007, 20h06   #8
NoDude
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Accessing Class Method

By the looks of it, you're looking for the singleton pattern.

final class Singleton{
private static $sql;
private static $dao;
private static $smarty;

public static function getSql(){
if(!isset(self::$sql)){
require CLASS_DIR.'Sql.php';
self::$sql = new Sql;
}
return self::$sql;
}

public static function getDao(){
if(!isset(self::$dao)){
require CLASS_DIR.'Dao.php';
self::$dao = new Dao;
}
return self::$dao;
}

public static function getSmarty(){
if(!isset(self::$smarty)){
require SMARTY_DIR.'Smarty.class.php';
self::$smarty = new Smarty;
//some config stuff
}
return self::$smarty;
}

//prevent construction/cloning
public function __construct(){
trigger_error("Singleton instantiation not allowed", E_USER_ERROR);
}

public function __clone(){
trigger_error("Singleton cloning not allowed", E_USER_ERROR);
}
}

Btw. Try to write an OO application in a manner that would not require
the require_once statement, but rather a plain require. In part,
because it's faster, but mainly because it will force you to write
your applications in a much straightforward manner. Maybe
straightforward isn't the word here, but I'm tired as hell...

On Sep 17, 9:18 pm, RageARC <rage...@gmail.com> wrote:
> Well I wouldn't lose reusability as all the classes are supposed to
> work together for main_class, thus providing a set of functions
> available in one single variable. It is built to be that way.
>
> I think I am gonna use that code I have posted. Seems to be better.
> And I never called my class functions static and I still could call
> them statically :S.



  Réponse avec citation
 
Page generated in 0,04906 seconds with 9 queries