Profic
just Profic (PHP5 BetaTeam)
[php5] interface arrayAcces & $this
Код:
Так вот в методе setA () не происходит установка массива. Вообще. Даже методы не вызываются. Так и должно быть?
Я конечно могу использовать
$this->offsetSet ('key', 'val');
или
$temp = $this;
$temp['key'] = 'val';
но это имхо криво.
Я прав или я не должен хотеть применения массивов на $this?
Код:
PHP:
class arr implements arrayAccess {
private $a = array ();
public function setA () {
$this['key'] = 'val';
}
public function offsetExists ($offset) {
echo 'Checking existens of offset ' . $offset . '<br>';
return array_key_exists ($offset, $this->a);
}
public function offsetGet ($offset) {
echo 'Getting offset ' . $offset . '<br>';
return $this->a[$offset];
}
public function offsetSet ($offset, $value) {
$this->a[$offset] = $value;
return true;
}
public function offsetUnset ($offset) {
echo 'Unsetting offset ' . $offset . '<br>';
unset ($this->a[$offset]);
return true;
}
}
$o = new arr ();
$o->setA ();
var_dump ($o);
Я конечно могу использовать
$this->offsetSet ('key', 'val');
или
$temp = $this;
$temp['key'] = 'val';
но это имхо криво.
Я прав или я не должен хотеть применения массивов на $this?