Crell published some interesting benchmarks in ‘Benchmarking magic’. He mentions the overhead of loading and parsing in PHP being a big bottle neck in the comments. My current project uses a few classes that kind of clutter the .module and aren’t always used. Having PHP magic functions on the mind I immediately started thinking about __autoload and Drupal. Paths are an issue for includes with Drupal modules… You never quite know where your module will be in an installation. You can also only have a single _autoload() function. So to keep life simple for myself I decided to stash args for drupal_get_path in my class names.
<?php
function __autoload($classname) {
$parts = explode('_', $classname);
$type = array_pop($parts);
$name = array_pop($parts);
$file = array_pop($parts);
$path = drupal_get_path($type, $name).'/class.'. $file .'.php';
include_once($path);
}
class module_mediaAPI_media {}
class module_transformer_transform {}
?>
This makes drupal try to load:
It would be nice to standardize an __autoload as Drupal starts taking advantage of more OO capabilities.
Maybe Crell would be nice enough to plan out some __autoload benchmarks in the future… hint hint