Skip to content

Instantly share code, notes, and snippets.

@we4tech
Created December 18, 2011 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save we4tech/1493369 to your computer and use it in GitHub Desktop.
Save we4tech/1493369 to your computer and use it in GitHub Desktop.
lazy loaded model
<?php
class LazyLoadedModel {
private $instance = null;
private $refId = null;
private $initiated = false;
public function __construct($refId, $user) {
$this->refId = $refId;
$this->instance = $user;
}
public function __call($name, $args) {
if (!$this->initiated) {
$this->loadData();
}
return $this->instance->$name($args);
}
private function loadData() {
$this->instance->setEmail('hasan@swi.com');
$this->instance->setName('nhm tanveer hossain');
$this->initiated = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment