note 103533 deleted from function.require-once by danbrown
| From: | danbrown@php.net | Date: | Mon, 18 Apr 2011 23:11:01 +0000 |
| Subject: | note 103533 deleted from function.require-once by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-178961@lists.php.net to get a copy of this message | ||
Note Submitter: spark at limao dot com dot br
----
using antoine dot pouch at mcgill dot ca's check
I made this version of import using class_exists and basename
<?php
function import($path=""){
$current = str_replace("\\","/",getcwd())."/";
$path = $current.str_replace(".","/",$path);
if(substr($path,-1) != "*") $path .= ".class.php";
foreach(glob($path) as $file){
$file = str_replace($current,"",$file);
if(is_dir($file)) import($file.".*");
if(substr($file,-10) != ".class.php") continue;
if(class_exists(basename($file,".class.php"))) continue;
require_once($file);
}
}
?>
so it's shorter, doesn't need the session running, but still needs the glob function, also
fully recursive.
usage:
<?php
import("path.to.File");
import("path.to.*");
import("path.*");
import("*");
?>
either will get File.class.php included
but the wildcard ones will get the other classes too.