If I have code which uses a static variable for caching purposes like this:
class BossParty
{
// ...
public function getTemplate()
{
static $template;
if ($template == null)
{
$template = BossTemplate::get($this->templateID);
}
return $template;
}
// ...
}
Will $template persist across different instances of BossParty? I’ve tried checking php.net, but all I can find is info about static class variables.
Yes, the static variable will persist across instances of the class.
Example:
Note that this is true for descendant classes too. If we had a class
Childthat extendedTest, callingparent::__construct(whether explicitly or implicitly) will use the same value of$foo.