imprint
When I posted my Idea of building a wrapper class for include_once and require_once, I didn't think, that the many php developer would like it. But I was wrong, fortunately.
Thanks to Mathias Taylor for benchmarking. Special thanks goes to Cristian Strian for his suggestion to optimize the class, and make it faster. That is the optimized wrapper class.
Usage:
<?php
require("includeWrapper.class.php");
includeWrapper::includeOnce("test.php");
includeWrapper::includeOnce("test.php");
includeWrapper::includeOnce("test.php");
print_r(includeWrapper::getPaths());
?>
Output:
Array
(
[test.php] => 1
)
The class itself.
<?php
class includeWrapper{
public static $paths = array();
public static function includeOnce($path_file){
if(!isset(self::$paths[$path_file])){
include($path_file);
self::$paths[$path_file] = true;
}
}
public static function requireOnce($path_file){
if(!isset(self::$paths[$path_file])){
require($path_file);
self::$paths[$path_file] = true;
}
}
// just for testing
public static function getPaths(){
return self::$paths;
}
}
?>
Recent comments
49 weeks 5 days ago
1 year 6 weeks ago
1 year 10 weeks ago
1 year 33 weeks ago
1 year 37 weeks ago
1 year 37 weeks ago
1 year 44 weeks ago
1 year 44 weeks ago
1 year 44 weeks ago
1 year 44 weeks ago