OM2 Posted July 24, 2008 Share Posted July 24, 2008 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 Link to comment https://forums.phpfreaks.com/topic/116319-solved-newbie-questions-include_once-or-include-another-question/ Share on other sites More sharing options...
trq Posted July 24, 2008 Share Posted July 24, 2008 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. Link to comment https://forums.phpfreaks.com/topic/116319-solved-newbie-questions-include_once-or-include-another-question/#findComment-598115 Share on other sites More sharing options...
OM2 Posted July 24, 2008 Author Share Posted July 24, 2008 thanks. Link to comment https://forums.phpfreaks.com/topic/116319-solved-newbie-questions-include_once-or-include-another-question/#findComment-598125 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.