I have a habit of using include() a lot in my php scripts. I would like to know is it a good approach. I just use include a lot because it makes code look-better for future-proof programming.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
make use of php autoloading function
example:
whenever you instantiate a new class. PHP automagically calls the __autoload function with one argument i.e the class name. consider the below example
when you instantiate the user object here the autoload function is called, it tries include the file from the same directory. (with reference to above autoload function). now you could implement your own logic to autoload classes. no matter in which directory it resides. for more information check out this link http://in.php.net/autoload.
Update:
@RepWhoringPeeHaa, you said it correct buddy. there are more benefits in using spl_autoload then simple autoloading function. the major benefit i see is that more than one function can be used or registered.
for example