note 116706 added to function.spl-autoload-register

From: Date: Fri, 13 Feb 2015 13:00:12 +0000
Subject: note 116706 added to function.spl-autoload-register
Groups: php.notes 
Request: Send a blank email to php-notes+get-201726@lists.php.net to get a copy of this message
This autoload will find every class you call if you put each one in a different file. It walks into every directory recursivly from the root you specify in the $root var. You can specify the folders ou don't want to walk in (e.g you won't find any class in a 'view' folder on an MVC project) in the $dir_to_not_look_in array; spl_autoload_register(function($class) { $root = 'my/root/path'; $file = $class . '.php'; $dir_to_not_look_in = array($directories, $to, $not, $look, $in); if(!function_exists('load')) { function load($dir, $file) { if(file_exists($dir . '/' . $file)) { require_once $dir . '/' . $file; } else { foreach(scandir($dir) as $value) { if(is_dir($dir. '/' . $value) && !in_array($value, $dir_to_no_look_in)) load($dir. '/' . $value, $file); } } }; } load($root, $file); }); ---- Server IP: 72.52.91.14 Probable Submitter: 193.48.132.5 ---- Manual Page -- http://php.net/manual/en/function.spl-autoload-register.php Edit -- https://master.php.net/note/edit/116706 Del: integrated -- https://master.php.net/note/delete/116706/integrated Del: useless -- https://master.php.net/note/delete/116706/useless Del: bad code -- https://master.php.net/note/delete/116706/bad+code Del: spam -- https://master.php.net/note/delete/116706/spam Del: non-english -- https://master.php.net/note/delete/116706/non-english Del: in docs -- https://master.php.net/note/delete/116706/in+docs Del: other reasons-- https://master.php.net/note/delete/116706 Reject -- https://master.php.net/note/reject/116706 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#201726) next »