Jump to content

[SOLVED] Newbie questions: include_once or include? + another question.


OM2

Recommended Posts

Dumb question: what's the difference between include_once and include?

Why do you need to have the first one?  I've programmed in many languages... and can't remember seeing something similar.

Let me know.

 

Second question:

 

I have:

 

include_once('../common/myControl.php');

 

Instead of this, is it OK to use:

 

include_once($_SERVER["DOCUMENT_ROOT"] . '/dir1/dir2/common/myControl.php');

 

I've tried the second one above: and it works fine.

Just wanted to know: will I run into trouble when doing something else!?

2nd one: a big help, since I can take the line and use it in several other places, where previously I would have to use several ../../../.. etc, to get to the correct directory.

 

Thanks.

 

 

OM

The main benefit to using include_once is that if you have any function definitions within the included file you cannot accidentally include the file more than once which would generate a 'cannot redefine function' error.

 

As for your second question, yes it is fine to do so and in fact I would recommend the second approach be used.

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.