Page 1 of 1

To __autoload() or not to __autoload()?

Posted: Mon Jun 23, 2008 2:45 am
by movedx
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.

Re: To __autoload() or not to __autoload()?

Posted: Mon Jun 23, 2008 3:01 am
by alex.barylski
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.

Re: To __autoload() or not to __autoload()?

Posted: Mon Jun 23, 2008 5:40 am
by movedx
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?

Re: To __autoload() or not to __autoload()?

Posted: Mon Jun 23, 2008 5:55 am
by onion2k
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.

Re: To __autoload() or not to __autoload()?

Posted: Mon Jun 23, 2008 6:16 am
by movedx
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.

Re: To __autoload() or not to __autoload()?

Posted: Mon Jun 23, 2008 7:31 am
by Kieran Huggins
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.

Re: To __autoload() or not to __autoload()?

Posted: Mon Jun 23, 2008 9:05 am
by movedx
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.

Re: To __autoload() or not to __autoload()?

Posted: Mon Jun 23, 2008 9:56 am
by Kieran Huggins
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()?

Posted: Mon Aug 25, 2008 8:52 am
by marcth
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