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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.