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;
}
}
?>
Just curious what is the point of this? Sorry, I've only been cranking away at php for about a year, so alot is still new.
That code is php5 correct? public and static won't work in php4?
I've just tried this hack out. It works but has problems passing vars
around.