rshadarack Posted November 15, 2006 Share Posted November 15, 2006 I'm attempting to build a site with a general php library, with different files such as database.php for database functions and string.php for string functions. Some of my database functions require string functions, so I include string.php in database.php. Now add on about 10 different library files, and things start to get complicated. I have no clue (without looking in my library) which files include other files. So I want to be able to include a file twice without getting a redeclaration error. Is there a php'y way to do this? I could mimic C++ and do:[code]if (!isset(DATABASE_PHP)) { DATABASE_PHP = 1; include("string.php"); ...rest of database.php code...}[/code]In all of the files. It's fairly ugly, but it works.Is there a better way? Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted November 15, 2006 Share Posted November 15, 2006 require_once() Quote Link to comment Share on other sites More sharing options...
rshadarack Posted November 15, 2006 Author Share Posted November 15, 2006 Oy, don't know why I haven't heard of that. Thanks. Quote Link to comment Share on other sites More sharing options...
Jenk Posted November 15, 2006 Share Posted November 15, 2006 Better manage you files and includes. Never have a library file run include, only controllers should include via a service locator or similar. Quote Link to comment 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.