Post by Qphoria » Fri Apr 15, 2011 1:43 am

So this is a question that has come up many times and most of those times it has come from me. Why don't we use PHP5's __autoload() magic function.

Daniel has expressed a distaste for autoload for reasons noone knows. Why anyone would want to pollute the code with excess includes is beyond me and including files before using them means that some files could be included unnecessarily if not actually used for that particular session.

But I've used autoload successfully in other projects and from the research on the topic, I see absolutely no reason to not be using it. Reviews of autoload are stellar:
http://stackoverflow.com/questions/1408 ... ing-in-php
http://stackoverflow.com/questions/4862 ... d-practice
http://stackoverflow.com/questions/3331 ... erformance

They only say the best practice is to use your own improved autoload function instead of the generic one to better taylor it for your system, which goes without saying anyway. All the other big names seem to be using autoload (interspire, drupal,

Some people believed there was a performance hit with autoload, but all signs point to that being incorrect:
http://www.phpgenious.com/2009/02/php-5 ... ad-method/

One point of autoload is to avoid performance hits by only loading what is needed. Either way, performance hits or gains are minor at best. The main functionality is to allow loading custom classes without needing to worry about manually including them. This allows you to extend and expand existing classes without having to worry about adding each one to the startup.php file and worry about losing those changes during an upgrade.

For OpenCart developers such as myself, this tends to be a pain when creating classes that can be expanded and probably why more people aren't creating classes for some things. The lack of autoload means you have to add additional includes manually to some files to the startup.php or other place.

OpenCart is leading the way in its overall theme and design, but 3rd party developers are constantly hindered by missing major features like autoload.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by phpuk » Fri Apr 15, 2011 1:50 am

Hi Qphoria,

I developed some code for the big D a while ago to demonstrate autoload in opencart but after a while he didn't reply any longer.

There is absolutely no reason not to use it as the benefits far out weigh ANY negative you can think of.

Phil.

Global Moderator

Posts

Joined
Wed Mar 25, 2009 10:57 am

Post by Johnathan » Fri Apr 15, 2011 1:58 am

I think all of Q's points are right on. My guess is that Daniel feels he would be losing some control over the code, which I understand not wanting to do. However, since there are definite benefits to doing this, I think that outweighs any distaste for losing structural control of includes.

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by Qphoria » Fri Apr 15, 2011 2:25 am

I'm not sure what control would be lost. It simply enables easier classing and subclassing for better 3rd party mods. OpenCart could use a extensible class library for common things like credit card forms, cart and others. The library classes are mostly final classes which means you can't subclass it to add features. So instead we edit the core directly and end up having core mods all over.

Granted that isn't an Autoload issue persay, but when talking about custom classes and libraries, these are things that can be easily added with autoload and just makes for a normal standardized utility part of any platform.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Johnathan » Fri Apr 15, 2011 5:14 am

Qphoria wrote:I'm not sure what control would be lost.
What I meant is that I think there could be a perceived loss of control over the code, which may be why Daniel doesn't want to use it. I agree that no control would actually be lost.

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by angelwebdesign » Sun Jul 24, 2011 9:45 pm

Surely the whole point of it being open source, is to allow the users to have a contribution. Doesn't have to mean that the main distribution gets changed by the users but makes it easy for users to contribute plugins, extensions and customise things the way they want to.

Web Design Wigan
Football Canvas Prints Powered by OpenCart



Posts

Joined
Sun Jul 24, 2011 9:17 pm
Location - Wigan, Greater Manchester, UK
Who is online

Users browsing this forum: No registered users and 6 guests