Been reading over the PHP4->5 changes again, and the __autoload magic function caught my eye. At first glance it looked like a wonderful solution to longer header files of inclues. However, the manual examples, at least, show a global function for the entire class space. Which basically would entail sticking all the classes into a single directory so it can find them... When you have lots of class that seems like enough of an annoyance to destroy its value.
Any one out there with experience using it?
Do you use __autoload in PHP5?
Moderator: General Moderators
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
- andre_c
- Forum Contributor
- Posts: 412
- Joined: Sun Feb 29, 2004 6:49 pm
- Location: Salt Lake City, Utah
i wrote a class with static variables that could be set to directories from which include classes.
i was trying to do something similar to namespaces, but it wasn't quite the same.
it was something like:
i was trying to do something similar to namespaces, but it wasn't quite the same.
it was something like:
Code: Select all
<?
class MOD {
public static $dirs; // array
public static function import($dir) {
// add the dir to static $dirs array
}
}
function __autoload ($class_name) {
foreach (MOD::$dirs as $dir) {
// include file if it exists on that directory
}
}
MOD::import('Dir.SubDir');
$p = new Page; // class in Dir/SubDir/Page.php
?>