DragonPrime - LoGD Resource Community
Welcome Guest
  • Good morning, Guest.
    Please log in, or register.
  • May 24, 2019, 11:05:33 AM
Home Forums News Downloads Login Register Advanced Search
* * *
DragonPrime Menu
Resource Pages

Pages: [1]   Go Down
Author Topic: require_onces / require in modules  (Read 9562 times)
0 Members and 1 Guest are viewing this topic.
« 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 =)

Offline Offline

Posts: 430


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.

Castle Siege - a work in progress
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.
Pages: [1]   Go Up
Jump to:  

DragonPrime Notices
Welcome to DragonPrime - The LoGD Resource Community!

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