On Mon, Oct 27, 2008 at 11:54 AM, Stut <stuttle@xxxxxxxxx> wrote: > On 27 Oct 2008, at 15:46, Alex Chamberlain wrote: >> >> Problem solved: >> function __autoload($c) { >> $m = array(); >> preg_match('/(?:^[A-Z][a-z]+)Controller/', $c, $m); >> if (count($m)) { >> require_once(realpath(FS_CONTROLLER . '/' . strtolower($m[0]) . >> '.inc.php')); >> } >> } >> >> However (perhaps a more appropriate question), do you think there is an >> easier/better way to do this?? > > See, that wasn't so hard was it!! > > Personally I'd have gone with something more like this... > > function __autoload($class) > { > if (substr($class, -10) == 'Controller') > { > // No need for realpath here, it's not doing anything useful > // The _once is probably redundant too, but it may be required > // depending on how your code is arranged. > require FS_CONTROLLER.'/'.strtolower($class).'.inc.php'; > } > } > > ...but there's always more than one solution. > > -Stut > > -- > http://stut.net/ > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > I'd just like to add spl autoload is friendlier since __autoload can only be defined once. http://us.php.net/manual/en/function.spl-autoload-register.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php