note 98687 added to language.oop5.autoload
| From: | takingsides at gmail dot com | Date: | Wed, 30 Jun 2010 15:15:44 +0000 |
| Subject: | note 98687 added to language.oop5.autoload | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-170605@lists.php.net to get a copy of this message | ||
file_exists would work perfectly fine, unless people intentionally create directories ending with
".php". However sometimes classes can be called either "MyClass.php" or
"MyClass.class.php"...
I have a number of configuration constants defined (before the autoload function) i.e:
<?php
// in: config.php
define('DEV_MODE', 1);
$error_reporting = error_reporting(DEV_MODE ? E_ALL : 0);
define('CONF_DIR_LIB', '/path/to/classes/');
?>
Finally inside the config.php after my constants, i define the autoload...
A. DEV_MODE when 1 or true, will show all errors.
B. DEV_MODE when 0 or false, will supress ALL errors including those thrown from inside classes.
<?php
// also in: config.php
function __autoload($f)
{
if (($f1 = file_exists($c1 = CONF_DIR_LIB . "$f.class.php"))
|| ($f2 = file_exists($c2 = CONF_DIR_LIB . "$f.php")))
if (DEV_MODE)
include_once ($f1 ? $c1 : $c2);
else
@include_once ($f1 ? $c1 : $c2);
}
?>
I hope this helps anyone :)
----
Server IP: 69.147.83.197
Probable Submitter: 81.137.71.201
----
Manual Page -- http://www.php.net/manual/en/language.oop5.autoload.php
Edit -- https://master.php.net/note/edit/98687
Del: integrated -- https://master.php.net/note/delete/98687/integrated
Del: useless -- https://master.php.net/note/delete/98687/useless
Del: bad code -- https://master.php.net/note/delete/98687/bad+code
Del: spam -- https://master.php.net/note/delete/98687/spam
Del: non-english -- https://master.php.net/note/delete/98687/non-english
Del: in docs -- https://master.php.net/note/delete/98687/in+docs
Del: other reasons-- https://master.php.net/note/delete/98687
Reject -- https://master.php.net/note/reject/98687
Search -- https://master.php.net/manage/user-notes.php