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? Link to comment https://forums.phpfreaks.com/topic/27301-includes-c-style/ Share on other sites More sharing options...
roopurt18 Posted November 15, 2006 Share Posted November 15, 2006 require_once() Link to comment https://forums.phpfreaks.com/topic/27301-includes-c-style/#findComment-124858 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. Link to comment https://forums.phpfreaks.com/topic/27301-includes-c-style/#findComment-124865 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. Link to comment https://forums.phpfreaks.com/topic/27301-includes-c-style/#findComment-124894 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.