Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.