Jump to content

Includes - C++ style


rshadarack

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.