Por desgracia no tengo PHP en este PC ni editores tampoco asi que voy a la ciega.
No te aseguro de que funccionara, pero si te canta algun error o problema dime y lo miro:
Código PHP:
<?php
class TableColorManager
{
private $_colors = array();
private $_currentColor = 0;
public function AddColor($color)
{
if(!is_string($color))
{
throw new Exception("\$color parameter must be a string");
}
if(preg_match('/^#[a-f0-9]{6}$/i', $color))
{
array_push($this->_colors, $color);
}
else
{
throw new Exception("Invalid color");
}
return $this;
}
public function getNextColor()
{
if($this->_currentColor > count($this->_colors) - 1)
{
$this->_currentColor = 0;
}
else
{
$this->_currentColor++;
}
return $this->_colors[$this->_currentColor];
}
}
$colors = new TableColorManager();
$colors->AddColor("#fff")->AddColor("#ff00ff");
$colors->AddColor("#000");
$colors->AddColor("#abc5e2");
for($i = 0; $i <= 10; $i++)
{
echo "Current color: " . $colors->getNextColor() . "<br />";
}
?>