Best way to fetch options

I am looking for the best way (fastest and saving mem) to fetch about 20 options in an addon.

In my case I need :
5 to 6 xenforo options
about 15 self created options
(3 xenforo native options are needed a couple of times and 6 selfcreated options also more than once - in for each loops for example)

I found 2 ways to do it:

  1. getting all options at beginning of code:
    $xenOptions = XenForo_Application::get('options')->getOptions();
    each option will be available by calling $xenOptions['optionName']
    ressources used once. but the array could be quite big, filled with options I dont need here.
  2. getting the options one by one:
    Thats ok, but if I have a loop like 50 times, will that take more ressources than just having the array above in 1.?
    Is there a ressource change if I add a "shorthand line" at beginning of code like
    $xenOptions = XenForo_Application::get('options')
    and calling each option with $xenOptions->optionName?
I know these are peanuts problems, but I want to do it the best way.
Is there a ressource difference? Or is it only a semantic difference?
I somehow like the look and feel of $xenOptions['optionName']...

Anybody have any thoughts?



XenForo Developer
Staff member
If you are fetching a single option:
$optionName = XenForo_Application::get('options')->optionName;
Or if you are fetching more than one:
$options = XenForo_Application::get('options');

$myStuff = $options->option1 + $options->option2 + $options->option3;