Here we have a couple of objects:
Code: Select all
class Shapes {
public $color;
public $sides;
public $lengths = array();
public function access($action,$prop,$value=NULL) {
switch ($action) {
case 'read':
$value = $this->$prop;
return($value);
break;
case 'write':
$this->$prop = $value;
return(1);
break;
}
}
}
class Polygon extends Shapes {
public function circumference() {
$circumference = 0;
foreach ($this->lengths as $key => $value) {
$circumference += $value;
}
return($circumference);
}
}Code: Select all
$polygon = new Polygon;
$polygon->access(write,sides,5);Code: Select all
$polygon->access(write,lengths[],4);Do I need to alter the access() method somehow? All help deeply appreciated.