note 50562 rejected from function.require-once by techtonik

From: Date: Tue, 13 Sep 2005 05:47:12 +0000
Subject: note 50562 rejected from function.require-once by techtonik
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-95093@lists.php.net to get a copy of this message
Note Submitter: ulderico at maber dot com dot br ---- For those who misses Java-like import , here's a handy implemention. It may not well handle Singletons and References, but I think it'll do fine for most cases... Hey people do not steal it, keep it GNU GPL please... The following code is preseverd by GNU GPL: function import($class){ $base_class = "PATHTO/WEB-INF/classes"; $class_strut = explode(".",$class); if(sizeof($class_strut)<1) trigger_error("too short class invocation"); if($class_strut[sizeof($class_strut)-1] == "*"){ $tmp_class_strut = $class_strut; unset($tmp_class_strut[sizeof($tmp_class_strut)-1]); $tmp_base_class = $base_class."/". implode("/",$tmp_class_strut); $d = dir($tmp_base_class); while (false !== ($entry = $d->read())) { if($entry == "." || $entry == "..") continue; require_once($tmp_base_class."/".$entry); } $d->close(); // Do you recognize this Example??? }else{ if(file_exists($base_class."/". implode("/",$class_strut).".class.php")) require_once($base_class."/". implode("/",$class_strut).".class.php"); else require_once($base_class."/". implode("/",$class_strut).".php"); } $vars = get_defined_vars(); foreach($vars as $var => $value){ $GLOBALS[$var] = $value; }// Hey remember you're inside a function, // you've got to globalise value here to outside... }

« previous php.notes (#95093) next »