maexus Posted March 18, 2006 Share Posted March 18, 2006 For my blog source, I have alot of custom functions that I need to include. It started to become a real pain so I've started to use one master include file that pulls in all the include files I need all at once. This seems like it would work, but having issues.Here is my master include file:[code]<?php#List all the files you wish to include...$includes = array( 'strings.inc.php', 'test.inc.php');require_once 'config.php';foreach($includes as $include){ require_once $include;}[/code]Now.. my config.php file is filled with constants. This is a fairly meaty file and really esentinal for the operation of the code. I call it first. Then I call all the includes in the array after that. Now, this setup works when I have like 3-4 include files and like 15 functions total. The more functions I have and the more files to include... I keep getting "Function 'test' is undefined" when it IS defined. If I include the file directly, it works just fine. Also, I call the config file before anything else, yet I can use the constants in there in other included files. The only solution I can see is to include the config.php for each include file. I tried that, and it still doesn't access the value for a constant.Can someone help me please. Quote Link to comment https://forums.phpfreaks.com/topic/5215-using-too-many-includesrequires/ Share on other sites More sharing options...
fusionpixel Posted March 18, 2006 Share Posted March 18, 2006 probably you are getting the undefines because there are functions runing before the variables needed they are loaded.have you considered a "loader" file rather than an array?<?#file holder name holder.phpinclude ('file1.php');include ('file2.php');....?>then on your actual fileinclude ('holder.php');Now, i havent tested this so I dont know if it will work. Quote Link to comment https://forums.phpfreaks.com/topic/5215-using-too-many-includesrequires/#findComment-18523 Share on other sites More sharing options...
maexus Posted March 18, 2006 Author Share Posted March 18, 2006 Well, I tried a simple test. I created a new test directory. In that dir, I created a dir called lib. In lib I have the master include file, as noted before. test.php and config.php.test.inc.php[code]<?phprequire_once 'config.php';function test(){ echo BASE_URL;}?>[/code]config.php[code]<?phpdefine('BASE_URL', 'http://localhost/test');?>[/code]and finally index.php[code]<?phprequire_once 'lib/master.php';test();?>[/code]I get BASE_URL outputted and not [a href=\"http://localhost/test\" target=\"_blank\"]http://localhost/test[/a]. Now, if I add require_once 'lib/config.php'; to index.php along with the master file, it outputs the constant value. ~_~ This completely defeats the purpose of using the master include. I think the problem may be with how I setup require_once. I don't know. I've been trying to figure this out for a while now. Quote Link to comment https://forums.phpfreaks.com/topic/5215-using-too-many-includesrequires/#findComment-18587 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.