Skip to content

Instantly share code, notes, and snippets.

@davidino
Created September 19, 2011 21:59
Show Gist options
  • Select an option

  • Save davidino/1227741 to your computer and use it in GitHub Desktop.

Select an option

Save davidino/1227741 to your computer and use it in GitHub Desktop.
lazy loading programming data mapper.
<?php
/**
*
*/
class ClassName {
public function setAuthor($fun)
{
$this->author = $fun;
}
public function getAuthor()
{
//is a function
return $this->author();
//the only solution ?
//return call_user_func( $this->author );
}
}
class Fake
{
protected $value;
public function __invoke()
{
if ($this->value)
{
return $value;
}
else
{
$this->value = 2;
return 2; // $this->mapper->find(...)
}
}
}
$d = new Fake;
$c = new ClassName();
$c->setAuthor($d);
echo $c->getAuthor();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment