Global variable (when a function is not an option)

Filling the global scope with variables is considered a bad practice and could cause other issues.

You can achieve what you want inside the page model you are already using:

protected $hints = null;

public function getHints()
{
    if (! is_null($this->hints)) {
        return $this->hints;
    }

    return $this->hints = // generate hints
}

The first time you call the method getHints() it will store the result in the $hints property and return it on subsequent calls.

If you need to modify the $hints property elsewhere, add a setHints() method that takes an argument and modify it in there.

2 Likes