Created
January 16, 2014 13:10
-
-
Save prigazzi/8454758 to your computer and use it in GitHub Desktop.
Pequeño ejemplo de Lazy Loading en una clase en PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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