I work in PHP.
I have a function (F1) called a variable number of times. Inside this function, I need to load a constant data set from another function (F2). It always loads the same data set, however loading the set involves some searches and database processing. Instead of calling F2 multiple times and increasing the overhead / overhead / processing requirements, I would like to cast the result into a static variable in F1. However, for some reason, it will not allow me to set the variable as static by calling a function.
Code example:
function calledRepeatedly() {
static $dataset = loadDataset();
return "stuff";
}
function loadDataset() {
return array(
"data1",
"data2"
);
}
The above does NOT work. This results in an error - unexpected '(', waiting for ',' or ';'.
, , , , , , Roupeatedly .
?