note 117241 added to function.spl-autoload-register
| From: | iam at thatguy dot co dot za | Date: | Fri, 08 May 2015 07:19:06 +0000 |
| Subject: | note 117241 added to function.spl-autoload-register | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-202472@lists.php.net to get a copy of this message | ||
<?php
// Example to auto-load class files from multiple directories using the SPL_AUTOLOAD_REGISTER
method.
// It auto-loads any file it finds starting with class.<classname>.php (LOWERCASE), eg:
class.from.php, class.db.php
spl_autoload_register(function($class_name) {
// Define an array of directories in the order of their priority to iterate through.
$dirs = array(
'project/', // Project specific classes (+Core Overrides)
'classes/', // Core classes example
'tests/', // Unit test classes, if using PHP-Unit
);
// Looping through each directory to load all the class files. It will only require a file
once.
// If it finds the same class in a directory later on, IT WILL IGNORE IT! Because of that
require once!
foreach( $dirs as $dir ) {
if (file_exists($dir.'class.'.strtolower($class_name).'.php')) {
require_once($dir.'class.'.strtolower($class_name).'.php');
return;
}
}
});
----
Server IP: 72.52.91.14
Probable Submitter: 152.111.16.61
----
Manual Page -- http://php.net/manual/en/function.spl-autoload-register.php
Edit -- https://master.php.net/note/edit/117241
Del: integrated -- https://master.php.net/note/delete/117241/integrated
Del: useless -- https://master.php.net/note/delete/117241/useless
Del: bad code -- https://master.php.net/note/delete/117241/bad+code
Del: spam -- https://master.php.net/note/delete/117241/spam
Del: non-english -- https://master.php.net/note/delete/117241/non-english
Del: in docs -- https://master.php.net/note/delete/117241/in+docs
Del: other reasons-- https://master.php.net/note/delete/117241
Reject -- https://master.php.net/note/reject/117241
Search -- https://master.php.net/manage/user-notes.php