To __autoload() or not to __autoload()?
Moderator: General Moderators
To __autoload() or not to __autoload()?
Hi,
I did a search of the forum to find any topics on the '__autoload()' function, but the results are messy. So I'll ask here: which do you guys prefer, the '__autoload()' method or the including and or requiring(_once) your classes?
I'm also interested to see how you guys implement '__autoload()', for those of you that do use the magic function.
Cheers.
I did a search of the forum to find any topics on the '__autoload()' function, but the results are messy. So I'll ask here: which do you guys prefer, the '__autoload()' method or the including and or requiring(_once) your classes?
I'm also interested to see how you guys implement '__autoload()', for those of you that do use the magic function.
Cheers.
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: To __autoload() or not to __autoload()?
Personally I have experimented with both, I can't really say one is better than the other.
On one hand, using require/include makes your source code explicit -- no magic which can confuse new developers. On the other hand, an include is something fairly redundant so as long as you make it clear to new developers that classes are included automagically, there should be little problem for new developers.
I don't mean just new developers either. Even in my own projects I take breaks, sometime extended breaks. When I come back to a project months later, if I can still read the code as if I left yesterday, I know it's done right.
On one hand, using require/include makes your source code explicit -- no magic which can confuse new developers. On the other hand, an include is something fairly redundant so as long as you make it clear to new developers that classes are included automagically, there should be little problem for new developers.
I don't mean just new developers either. Even in my own projects I take breaks, sometime extended breaks. When I come back to a project months later, if I can still read the code as if I left yesterday, I know it's done right.
Re: To __autoload() or not to __autoload()?
I was thinking of having a 'kernel.inc.php' and simply have that have the autoload function in it - two of them, one for read-only classes for "customer facing" pages, and read/write-classes fopr the administration panel - and then just include the kernel into each page requiring the classes.
Thoughts?
Thoughts?
Re: To __autoload() or not to __autoload()?
Autoloading in your own websites is great, and I'd recommend it every time.
If you're writing code that other people will integrate into their sites though... then I'd be a bit more wary of it.
If you're writing code that other people will integrate into their sites though... then I'd be a bit more wary of it.
Re: To __autoload() or not to __autoload()?
My sites are basically customer's websites. I've done a few websites for sel employed individuals and I want to start writting apps in a more professional manner to make the whole job easier.
Form generation is some what of a boring task for me, and very tedious.
Form generation is some what of a boring task for me, and very tedious.
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
Re: To __autoload() or not to __autoload()?
I like __autoload(), but it's really a personal choice.
it can be a nice time saver if you're building a fairly simple app or something modular, but it can also lead to headaches as it adds one more layer of "magic" to doubt when something goes awry.
Try it on, see how it feels. It may shrink during the first wash.
it can be a nice time saver if you're building a fairly simple app or something modular, but it can also lead to headaches as it adds one more layer of "magic" to doubt when something goes awry.
Try it on, see how it feels. It may shrink during the first wash.
Re: To __autoload() or not to __autoload()?
I do try to make my applications/sites as modular as possible. I follow the MVC is my own broken way.
about.class.php = Controller. Contains the 'About_Page' class which acts as a controller for the view, about.php. Then there's about.tmpl which is the template file.
Simple as that really. Can you guys recommend any libs or frameworks that will generate forms based on data that has been passed into it? I don't fancy writing forms out my self manually - it's annoying.
Cheers.
about.class.php = Controller. Contains the 'About_Page' class which acts as a controller for the view, about.php. Then there's about.tmpl which is the template file.
Simple as that really. Can you guys recommend any libs or frameworks that will generate forms based on data that has been passed into it? I don't fancy writing forms out my self manually - it's annoying.
Cheers.
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
Re: To __autoload() or not to __autoload()?
There's currently one hell of a design discussion going on about a form generator. Maybe arborint has some code that could be released separately from the framework in question?
Re: To __autoload() or not to __autoload()?
I wouldn't use the __autoload() function. Use the spl_autoload_register() function instead--that way you can add several autoload functions in your site if need be.
Marc
Marc