What is a good way to check if an instance variable has never been assigned. Consider the following example. $this->foo is null to start. If $this->foo is found in the database, subsequent calls to getFoo() won't query the database. However, if there is nothing in the database that gets returned(null) all subsequent calls still hit the database..not good.
class FooBar
{
protected $foo;
protected $db;
public function getFoo()
{
if (is_null($this->foo)) {
$this->foo = $this->db->getFooFromDatabase();
}
return $this->foo;
}
}