Reputation: 1218
Are the results of functions being cached internally by PHP?
Simple example:
public function calc($arg){
return pow($arg,0.5);
}
echo calc(5) . "<br>";
echo calc(5) . "<br>";
Will PHP caculate calc() twice, or will it recognize that the argument hasn't changed and give me some kind of cached result?
Upvotes: 1
Views: 589
Reputation: 31614
If you have opcache installed then PHP will cache the operational code, or opcode. These are the machine level instructions that PHP runs. In other words, PHP is caching how to run your function, not the results or the output of running it with a given data set.
If you want to save the value of your run, you should store the result in a variable and reference that instead of calling the function over and over
$data = calc(5);
Upvotes: 3