note 103533 added to function.require-once

From: Date: Mon, 18 Apr 2011 22:25:17 +0000
Subject: note 103533 added to function.require-once
Groups: php.notes 
Request: Send a blank email to php-notes+get-178957@lists.php.net to get a copy of this message
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. ---- Server IP: 69.147.83.197 Probable Submitter: 187.55.215.170 ---- Manual Page -- http://www.php.net/manual/en/function.require-once.php Edit -- https://master.php.net/note/edit/103533 Del: integrated -- https://master.php.net/note/delete/103533/integrated Del: useless -- https://master.php.net/note/delete/103533/useless Del: bad code -- https://master.php.net/note/delete/103533/bad+code Del: spam -- https://master.php.net/note/delete/103533/spam Del: non-english -- https://master.php.net/note/delete/103533/non-english Del: in docs -- https://master.php.net/note/delete/103533/in+docs Del: other reasons-- https://master.php.net/note/delete/103533 Reject -- https://master.php.net/note/reject/103533 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#178957) next »