[UPHPU] require_once vs. class_exists

Rusty Keele rusty.keele at yahoo.com
Fri Apr 18 11:04:24 MDT 2008

Sean <sean at lookin3d.com> wrote: This IMHO is the best way. Also the most optimal. The reason is you may 
or may not need to the class you are including at the top of your 
script. It could be contingent on a condition(s)


include 'Some_Class.php';

if(someCondition) {
    $class = new Some_Class();
} else {

__autoload make this more optimal by only including the classes you are 
actually using.


> There is also a 3rd way... Autoloading.
> http://us2.php.net/autoload
> You can write your own custom __autoload function to require the files
> you need if a class doesn't exists.  It is very similar to #2, but can
> automate it for all classes.
> --lonnie


    Good point about autoloading.  After reading the PHP manual entry for class_exists() I see that it has an optional second argument (default is TRUE) which will cause PHP to attempt to autoload the class if it doesn't exist.


    This makes me think that using class_exist() is a good way to go because you get __autoload for free!


Be a better friend, newshound, and know-it-all with Yahoo! Mobile.  Try it now.

More information about the UPHPU mailing list