DragonPrime - LoGD Resource Community
Welcome Guest
  • Good evening, Guest.
    Please log in, or register.
  • December 14, 2017, 10:30:57 PM
Home Forums News Downloads Login Register Advanced Search
* * *
DragonPrime Menu
Login
 
 
Resource Pages
Search

Pages: [1]   Go Down
  Print  
Author Topic: require_onces / require in modules  (Read 8595 times)
0 Members and 1 Guest are viewing this topic.
Nightborn
Guest
« on: April 13, 2006, 12:02:21 PM »

If you use the require_once / require functions please use them where there have most effect...

Do not use them at the start of your module outside of every function *unless* you need the functions it will provide or the code it contains in every single function of your module (means in the get_info, the do_hook, the _run) which is very unlikely.

Use them at best where you need them.
I.e. if you have 3 cases where one will affect alignment call the require_once("modules/alignment/func.php"); just in this case and leave the others out.

You will save ressources this way and the module gets more slim.

Thanks =)

Logged
GenmaC
Moderator
Codemeister
*****
Offline Offline

Posts: 430

Coder


View Profile WWW
« Reply #1 on: March 07, 2007, 04:16:23 PM »

It's also important to note that using include_once or require_once is almost always better than the alternative.

If you have two seperate modules hooking on the same hook and both are require("lib/systemmail.php") for instance, you will get a "cannot redefine function systemmail" error - so you'd want to use require_once instead of just require.  If you are distributing your module you'd almost definetely want to use require_once instead of require in case someone else was requiring the same lib on that hook.
Logged



Castle Siege - a work in progress
Adept
Codemeister
****
Offline Offline

Posts: 279

I'm a llama!


View Profile WWW
« Reply #2 on: March 07, 2007, 10:52:12 PM »

yeah always use "_once"
only one exception where you can't

when there is code you need in the required module that is NOT wrapped in a function and it runs more than once in your module. this is in almost all cases a very poor programming practice and i have never seen a core module that does this.
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  


*
DragonPrime Notices
Version 1.1.2 is the current supported version and is available for download.

Support Us
No funds raised yet this year
Your help is greatly appreciated!
Recent Topics
DragonPrime LoGD
Who's Online
15 Guests, 0 Users
Home Forums News Downloads Login Register Advanced Search