I have ~100 string variables that need to be available on every webpage of a PHP site. The data will never change at runtime, though in the future I will need multiple sets of the data and to switch between the one in use for a page request. The length of the strings vary from 5 to 600 characters. I'm currently including a file that has the data like this:
$someStuff = "abc";
$otherStuff = "def";
// etc
I am using opcache. How much will this approach benefit from opcache?
I've seen this answer. I could change to using an associative array if the caching benefits were worth doing key lookups. However, it isn't clear to me if using a class with a static array field is better for my situation than declaring variables.
Maybe a function with a static variable is a good idea? Is this the same, better or worse than a static class field?
function getItem ($name) {
static $items = array("someStuff" => "abc");
return $items[$name];
}
Maybe a function instead of a variable for each string? Would this be better if not all the strings are used for a given page (which is often the case)?
function someStuff () { return "abc"; }
function otherStuff () { return "def"; }
What is the best solution? The data is needed on every page so I would like to be as efficient as possible, avoid reading from disk/database, etc.