protected function cachedInstance() {
        $findInstance = function($id, $cache) use (&$findInstance) {
            self::selectIds($id, $ids);

            if (array_key_exists($id, $cache)) {
                return (empty($ids)) ?
                        $cache[$id] : $findInstance($id, $cache[$id]);
            }

            return null;
        };

        foreach ($this->cacheIds() as $id) {
            $instance = $findInstance($id, self::$cache);
            if ($instance != null) {
                return $instance;
            }
        }

        return null;
    }
protected function cachedInstance() {
        $findInstance = function($id, $cache) use (&$findInstance) {
            self::selectIds($id, $ids);

            if (array_key_exists($id, $cache)) {
                return (empty($ids)) ?
                        $cache[$id] : $findInstance($id, $cache[$id]);
            }

            return null;
        };

        foreach ($this->cacheIds() as $id) {
            $instance = $findInstance($id, self::$cache);
            if ($instance != null) {
                return $instance;
            }
        }

        return null;
    }
protected function cachedInstance ( ) { $ findInstance = function ( $ id , $ cache ) use ( & $ findInstance ) { self :: selectIds ( $ id , $ ids ) ; if ( array_key_exists ( $ id , $ cache ) ) { return ( empty ( $ ids ) ) ? $ cache [ $ id ] : $ findInstance ( $ id , $ cache [ $ id ] ) ; } return null ; } ; foreach ( $ this -> cacheIds ( ) as $ id ) { $ instance = $ findInstance ( $ id , self :: $ cache ) ; if ( $ instance != null ) { return $ instance ; } } return null ; }
If available, returns the cached instance for the object it is called on

This may be used to either replace an initial object with a completely
cached instance of the same ID or to compare a modified object with the
copy that was cached before.

@see cacheIds()
If available returns the cached instance for the object it is called on