[UPHPU] require_once vs. class_exists

Scott Mattocks scott at crisscott.com
Fri Apr 18 11:22:42 MDT 2008


Rusty Keele wrote:

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

Disclaimer: We use __autoload here at work, but that is not my choice.

Keep in mind that using __autoload can lead to bad habits. It tends to 
make a developer lazy. Just expecting things to be there without 
checking can cause trouble down the road because you didn't take the 
time to check for the classes or files when you wrote the code. Now you 
don't really know what file you should be looking for or if the class 
was ever really written. A typo in a class name will give you an error 
that is not as detailed and/or accurate as it would have been if you had 
used require_once. The location of the error will be your __autoload 
function and not where the class was instantiated. Unless you have some 
extra error handling, it will be hard to find where the error occurred.

-- 
Scott Mattocks
Author: Pro PHP-GTK
http://www.crisscott.com


More information about the UPHPU mailing list