note 86477 modified in language.oop5.autoload by danbrown
| From: | danbrown@php.net | Date: | Tue, 21 Oct 2008 19:46:41 +0000 |
| Subject: | note 86477 modified in language.oop5.autoload by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-145544@lists.php.net to get a copy of this message | ||
Building on Chris Continanza's function, I wanted to add in multiple filename options since
sometimes I add ".class.php" and other times ".php".
<?php
function __autoload($class_name) {
$include_path = get_include_path();
$include_path_tokens = explode(':', $include_path);
foreach($include_path_tokens as $prefix){
$path[0] = $prefix . '/' . $class_name . '.php';
$path[1]= $prefix . '/' . $class_name . '.class.php';
foreach($path as $thisPath){
if(file_exists($thisPath)){
require_once $thisPath;
return;
}
}
}
}
?>
--was--
Building on Chris Continanza's function, I wanted to add in multiple filename options since
sometimes I add ".class.php" and other times ".php".
<?
function __autoload($class_name) {
$include_path = get_include_path();
$include_path_tokens = explode(':', $include_path);
foreach($include_path_tokens as $prefix){
$path[0] = $prefix . '/' . $class_name . '.php';
$path[1]= $prefix . '/' . $class_name . '.class.php';
foreach($path as $thisPath){
if(file_exists($thisPath)){
require_once $thisPath;
return;
}
}
}
}
?>
http://php.net/manual/en/language.oop5.autoload.php