[eluser]Pascal Kriete[/eluser]
How about a factory?
Code:
class Schedule_team
{
// Stores objects
private static $_teams = array();
// Regular class variables
public $name;
// Constructor - factory does most of the work
public function __construct() {}
// Factory
public static function factory($name)
{
if ( ! isset(Schedule_team::$_teams[$name]))
{
$team = new Schedule_team();
$team->name = $name;
Schedule_team::$_teams[$name] = $team;
}
else
{
$team = Schedule_team::$_teams[$name];
}
return $team;
}
}
Make that a library, and use it:
Code:
$this->load->library('schedule_team');
$a = Schedule_team::factory('ateam');
$b = Schedule_team::factory('bteam');
echo $a->name, ' ', $b->name;
In it's current form it will also return a team if you already have on of the same name. Depending on how complex this class is you may want to separate the factory from the actual schedule_team class.