Skip to content

Instantly share code, notes, and snippets.

@prigazzi
Created January 16, 2014 13:10
Show Gist options
  • Save prigazzi/8454758 to your computer and use it in GitHub Desktop.
Save prigazzi/8454758 to your computer and use it in GitHub Desktop.
Pequeño ejemplo de Lazy Loading en una clase en PHP
<?php
class User {
private $_db = null;
public function setDB(DBClass $db) {
return $this->_db = $db;
}
public function getDB() {
if(null == $this->_db) {
$this->setDB(new DBClass());
}
return $this->_db;
}
public function getUserByID() {
$this->getDB()->query(...)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment