- strtoupper: documentation ( source)
- method_exists: documentation ( source)
- ucfirst: documentation ( source)
<?php
class Correct {
protected $fields = array(
'one' => 'foo',
'two' => 'bar'
);
public function __get($value) {
$method = 'get' . ucfirst($value);
if(method_exists($this, $method)) {
return $this->$method();
}
return $this->fields[$value];
}
public function getOne() {
return strtoupper($this->fields['one']);
}
}
$cor = new Correct;
echo $cor->one;
echo $cor->two;