include_once Wrapper Class

There hase been some discussion in the recend days about the performance of include_once. Inlude_once is really slower than include. For the inclusion of the classes you can use
class_exists('PEAR') or require_once 'PEAR.php' (www.akbkhome.com/blog...);

You can also use this wrapper class for include_once and require_once, it is faster.

<?php
class includeWrapper{
    private static 
$paths = array();
    public static function 
includeOnce($path_file){
        if(!
in_array($path_file,self::$paths)){
            include(
$path_file);
            
self::$paths[] = $path_file;
        }
    }
    public static function 
requireOnce($path_file){
        if(!
in_array($path_file,self::$paths)){
            require(
$path_file);
            
self::$paths[] = $path_file;
        }
    }
}
includeWrapper::includeOnce("Class1.class.php");
includeWrapper::requireOnce("Class1.class.php");
includeWrapper::includeOnce("Class2.class.php");
?>

10 comments

Reply

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

Datenschutz | Impressum