how to include file using function ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
PHPycho
Forum Contributor
Posts: 336
Joined: Fri Jan 06, 2006 12:37 pm

how to include file using function ?

Post by PHPycho »

hello forums !!
i would like to know if its possible to include file in a function..ie when a filename is given as an argument then it should be able to include that..
index.php

Code: Select all

doInclude("page1");
functions.php

Code: Select all

doInclude($file){
 return include($file.".php");
}
Will this function work ? else what s the effective function then, I would also like to make one for class files(to include it and create objects).
please Help.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

For functions and classes, it will work. For variables, generally it will not. As for functionality to create objects, that's what Factories are for.
Post Reply