You are here: Re: Accessing Class Method « PHP Programming Language « IT news, forums, messages
Re: Accessing Class Method

Posted by NoDude on 09/17/07 19:06

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.

 

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

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