Re: preg_match
| From: | Stut | Date: | Mon, 27 Oct 2008 15:54:10 +0000 |
| Subject: | Re: preg_match | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-282499@lists.php.net to get a copy of this message | ||
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/