php - retrieving in-memory cached objects as a reference -


i'm using static method of class never instantiated create objects. objects differentiated id value. i'm trying cache objects subsequent requests of same id return reference created object.

demonstration code below:

class abc {    static $cache = array();     static function get( $id )    {       if ( isset( static::$cache[$id] ) )       {          return static::$cache($id);       }        static::$cache[$id] = new abc();       return static::$cache[$id];    } }  $ids = array(1,1,1,2);  foreach( $ids $id ) {    abc::get($id); } 

this not work. when change value of 1 object independent of other objects same id. tried placing '&' in front of function name , before method call no avail.

two questions: 1. how can this. 2. necessary or there better way?

thanks.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -