note 54333 added to language.oop5.autoload
| From: | sr at brightlight dot ch | Date: | Thu, 30 Jun 2005 16:43:50 +0000 |
| Subject: | note 54333 added to language.oop5.autoload | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-91215@lists.php.net to get a copy of this message | ||
I hope this helps some people:
<?php
function __autoload($name) {
$class = $interface = false;
// interface first
if (include_exists("interface.$name.inc")) {
include_once("interface.$name.inc");
$interface = true;
}
// class later
if (include_exists("class.$name.inc")) {
include_once("class.$name.inc");
$class = true;
}
// catch error
if ($class === false && $interface === false) {
trigger_error("Failed to include class/interface $name", E_USER_WARNING);
return false;
}
return true;
}
function include_exists($file)
{
static $include_dirs = null;
static $include_path = null;
// set include_dirs
if (is_null($include_dirs) || get_include_path() !== $include_path) {
$include_path = get_include_path();
foreach (split(PATH_SEPARATOR, $include_path) as $include_dir) {
if (substr($include_dir, -1) != '/') {
$include_dir .= '/';
}
$include_dirs[] = $include_dir;
}
}
if (substr($file, 0, 1) == '/') { //absolute filepath - what about file:///?
return (file_exists($file));
}
if ((substr($file, 0, 7) == 'http://' || substr($file, 0, 6)
== 'ftp://') && ini_get('allow_url_fopen')) {
return true;
}
foreach ($include_dirs as $include_dir) {
if (file_exists($include_dir.$file)) {
return true;
}
}
return false;
}
?>
----
Manual Page -- http://www.php.net/manual/en/language.oop5.autoload.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+54333
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54333&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54333&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54333&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54333&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54333&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54333&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+54333&report=yes
Search -- http://master.php.net/manage/user-notes.php