note 72831 added to language.oop5.autoload

From: Date: Fri, 02 Feb 2007 15:19:42 +0000
Subject: note 72831 added to language.oop5.autoload
Groups: php.notes 
Request: Send a blank email to php-notes+get-122560@lists.php.net to get a copy of this message
Note to Ricos posting: A lot of useless Coding. However, I improved the code, so now it will be able to find any folders ("." and ".." will not being tested... oO) and search as deep as possible. Now it will find CLASS_DIR/foo/bar.class.php also like CLASS_DIR/foo/bar/baz/buz/fii/and/so/on/class.php Warning: This code will check ALL dirs who're "deeper" / "lower" than the class dir, so prevent deeply hidden files (or use just a few folders). Improved Version: <?php // change this, if this code isn't "higher" than ALL classfiles define("CLASS_DIR", dirname(__FILE__)); /** * autoload classes (no need to include them one by one) * * @uses classFolder() * @param $className string */ function __autoload($className) { $folder = classFolder($className); if($folder) require_once($folder.$className.".class.php"); } /** * search for folders and subfolders with classes * * @param $className string * @param $sub string[optional] * @return string */ function classFolder($className, $sub = "/") { $dir = dir(CLASS_DIR.$sub); if(file_exists(CLASS_DIR.$sub.$className.".class.php")) return CLASS_DIR.$sub; while(false !== ($folder = $dir->read())) { if($folder != "." && $folder != "..") { if(is_dir(CLASS_DIR.$sub.$folder)) { $subFolder = classFolder($className, $sub.$folder."/"); if($subFolder) return $subFolder; } } } $dir->close(); return false; } ?> ---- Server IP: 194.153.94.10 Probable Submitter: 84.72.101.249 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.autoload.php Edit -- https://master.php.net/note/edit/72831 Del: integrated -- https://master.php.net/note/delete/72831/integrated Del: useless -- https://master.php.net/note/delete/72831/useless Del: bad code -- https://master.php.net/note/delete/72831/bad+code Del: spam -- https://master.php.net/note/delete/72831/spam Del: non-english -- https://master.php.net/note/delete/72831/non-english Del: in docs -- https://master.php.net/note/delete/72831/in+docs Del: other reasons-- https://master.php.net/note/delete/72831 Reject -- https://master.php.net/note/reject/72831 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#122560) next »