src/xPDO/Om/xPDOObject.php
public static function load(xPDO & $xpdo, $className, $criteria, $cacheFlag= true) {
        $instance= null;
        $fromCache= false;
        if ($className= $xpdo->loadClass($className)) {
            if (!is_object($criteria)) {
                $criteria = $xpdo->getCriteria($className, $criteria, $cacheFlag);
            }
            if ($criteria instanceof xPDOCriteria) {
                $criteria = $xpdo->addDerivativeCriteria($className, $criteria);
                $row= null;
                if ($xpdo->_cacheEnabled && $criteria->cacheFlag && $cacheFlag) {
                    $row= $xpdo->fromCache($criteria, $className);
                }
                if ($row === null || !is_array($row)) {
                    if ($rows= xPDOObject :: _loadRows($xpdo, $className, $criteria)) {
                        $row= $rows->fetch(\PDO::FETCH_ASSOC);
                        $rows->closeCursor();
                    }
                } else {
                    $fromCache= true;
                }
                if (!is_array($row)) {
                    if ($xpdo->getDebug() === true) $xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Fetched empty result set from statement: " . print_r($criteria->sql, true) . " with bindings: " . print_r($criteria->bindings, true));
                } else {
                    $instance= xPDOObject :: _loadInstance($xpdo, $className, $criteria, $row);
                    if (is_object($instance)) {
                        if (!$fromCache && $cacheFlag && $xpdo->_cacheEnabled) {
                            $xpdo->toCache($criteria, $instance, $cacheFlag);
                            if ($xpdo->getOption(xPDO::OPT_CACHE_DB_OBJECTS_BY_PK) && ($cacheKey= $instance->getPrimaryKey()) && !$instance->isLazy()) {
                                $pkCriteria = $xpdo->newQuery($className, $cacheKey, $cacheFlag);
                                $xpdo->toCache($pkCriteria, $instance, $cacheFlag);
                            }
                        }
                        if ($xpdo->getDebug() === true) $xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Loaded object instance: " . print_r($instance->toArray('', true), true));
                    }
                }
            } else {
                $xpdo->log(xPDO::LOG_LEVEL_ERROR, 'No valid statement could be found in or generated from the given criteria.');
            }
        } else {
            $xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Invalid class specified: ' . $className);
        }
        return $instance;
    }
public static function load(xPDO & $xpdo, $className, $criteria, $cacheFlag= true) {
        $instance= null;
        $fromCache= false;
        if ($className= $xpdo->loadClass($className)) {
            if (!is_object($criteria)) {
                $criteria = $xpdo->getCriteria($className, $criteria, $cacheFlag);
            }
            if ($criteria instanceof xPDOCriteria) {
                $criteria = $xpdo->addDerivativeCriteria($className, $criteria);
                $row= null;
                if ($xpdo->_cacheEnabled && $criteria->cacheFlag && $cacheFlag) {
                    $row= $xpdo->fromCache($criteria, $className);
                }
                if ($row === null || !is_array($row)) {
                    if ($rows= xPDOObject :: _loadRows($xpdo, $className, $criteria)) {
                        $row= $rows->fetch(\PDO::FETCH_ASSOC);
                        $rows->closeCursor();
                    }
                } else {
                    $fromCache= true;
                }
                if (!is_array($row)) {
                    if ($xpdo->getDebug() === true) $xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Fetched empty result set from statement: " . print_r($criteria->sql, true) . " with bindings: " . print_r($criteria->bindings, true));
                } else {
                    $instance= xPDOObject :: _loadInstance($xpdo, $className, $criteria, $row);
                    if (is_object($instance)) {
                        if (!$fromCache && $cacheFlag && $xpdo->_cacheEnabled) {
                            $xpdo->toCache($criteria, $instance, $cacheFlag);
                            if ($xpdo->getOption(xPDO::OPT_CACHE_DB_OBJECTS_BY_PK) && ($cacheKey= $instance->getPrimaryKey()) && !$instance->isLazy()) {
                                $pkCriteria = $xpdo->newQuery($className, $cacheKey, $cacheFlag);
                                $xpdo->toCache($pkCriteria, $instance, $cacheFlag);
                            }
                        }
                        if ($xpdo->getDebug() === true) $xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Loaded object instance: " . print_r($instance->toArray('', true), true));
                    }
                }
            } else {
                $xpdo->log(xPDO::LOG_LEVEL_ERROR, 'No valid statement could be found in or generated from the given criteria.');
            }
        } else {
            $xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Invalid class specified: ' . $className);
        }
        return $instance;
    }
public static function load ( xPDO & $ xpdo , $ className , $ criteria , $ cacheFlag = true ) { $ instance = null ; $ fromCache = false ; if ( $ className = $ xpdo -> loadClass ( $ className ) ) { if ( ! is_object ( $ criteria ) ) { $ criteria = $ xpdo -> getCriteria ( $ className , $ criteria , $ cacheFlag ) ; } if ( $ criteria instanceof xPDOCriteria ) { $ criteria = $ xpdo -> addDerivativeCriteria ( $ className , $ criteria ) ; $ row = null ; if ( $ xpdo -> _cacheEnabled && $ criteria -> cacheFlag && $ cacheFlag ) { $ row = $ xpdo -> fromCache ( $ criteria , $ className ) ; } if ( $ row === null || ! is_array ( $ row ) ) { if ( $ rows = xPDOObject :: _loadRows ( $ xpdo , $ className , $ criteria ) ) { $ row = $ rows -> fetch ( \ PDO :: FETCH_ASSOC ) ; $ rows -> closeCursor ( ) ; } } else { $ fromCache = true ; } if ( ! is_array ( $ row ) ) { if ( $ xpdo -> getDebug ( ) === true ) $ xpdo -> log ( xPDO :: LOG_LEVEL_DEBUG , "Fetched empty result set from statement: " . print_r ( $ criteria -> sql , true ) . " with bindings: " . print_r ( $ criteria -> bindings , true ) ) ; } else { $ instance = xPDOObject :: _loadInstance ( $ xpdo , $ className , $ criteria , $ row ) ; if ( is_object ( $ instance ) ) { if ( ! $ fromCache && $ cacheFlag && $ xpdo -> _cacheEnabled ) { $ xpdo -> toCache ( $ criteria , $ instance , $ cacheFlag ) ; if ( $ xpdo -> getOption ( xPDO :: OPT_CACHE_DB_OBJECTS_BY_PK ) && ( $ cacheKey = $ instance -> getPrimaryKey ( ) ) && ! $ instance -> isLazy ( ) ) { $ pkCriteria = $ xpdo -> newQuery ( $ className , $ cacheKey , $ cacheFlag ) ; $ xpdo -> toCache ( $ pkCriteria , $ instance , $ cacheFlag ) ; } } if ( $ xpdo -> getDebug ( ) === true ) $ xpdo -> log ( xPDO :: LOG_LEVEL_DEBUG , "Loaded object instance: " . print_r ( $ instance -> toArray ( '' , true ) , true ) ) ; } } } else { $ xpdo -> log ( xPDO :: LOG_LEVEL_ERROR , 'No valid statement could be found in or generated from the given criteria.' ) ; } } else { $ xpdo -> log ( xPDO :: LOG_LEVEL_ERROR , 'Invalid class specified: ' . $ className ) ; } return $ instance ; }
Load an instance of an xPDOObject or derivative class.

@static
@param xPDO &$xpdo A valid xPDO instance.
@param string $className Name of the class.
@param mixed $criteria A valid primary key, criteria array, or
xPDOCriteria instance.
@param bool|int $cacheFlag Indicates if the objects should be cached and
optionally, by specifying an integer value, for how many seconds.
@return object|null An instance of the requested class, or null if it
could not be instantiated.
Load an instance of an xPDOObject or derivative class .