|
Posted by ZeldorBlat on 03/25/07 18:35
On Mar 25, 1:03 pm, Michael Daly <MichaelD...@foo.bar> wrote:
> shimmyshack wrote:
>
> Thanks for the info.
>
> > but in general for other reasons it is a good idea to modularise your
> > code, something like jpgraph
>
> Yeah - I've been sloppy up to now and all classes are defined in a
> single file. I intend to split it into one file per class. However, I
> figure that with all the require_once statements, at run time it will be
> like loading a single big file anyway, no?
>
> Mike
That's what __autload is for:
<http://www.php.net/autoload>
Here's the idea: when a class is referenced and it isn't yet defined,
the __autoload function is called with the class name. This gives you
an opportunity to load it. Furthermore, you'll only end up loading
what you need and you won't need all those require_once() statements.
All my classes live in their own files where the file is named after
the class. I have a file called autoload.php that I include at the
top of all my pages. Inside I have something like this:
if(!function_exists('__autoload')) {
function __autoload($class_name) {
require_once $class_name . '.php';
}
}
Navigation:
[Reply to this message]
|