PHP 5.3 and interface \ArrayAccess
- by Jakub Lédl
I'm now working on a project and I have one class that implements the ArrayAccess interface.
Howewer, I'm getting an error that says that my implementation:
must be compatible with that of ArrayAccess::offsetSet().
My implementation looks like this:
public function offsetSet($offset, $value) {
  if (!is_string($offset)) {
    throw new \LogicException("...");
  }
  $this->params[$offset] = $value;
}
So, to me it looks like my implementation is correct. Any idea what is wrong? Thanks very much!
The class look like this:
class HttpRequest implements \ArrayAccess {
  // tons of private variables, methods for working
  // with current http request etc. Really nothing that
  // could interfere with that interface.
  // ArrayAccess implementation
  public function offsetExists($offset) {
    return isset ($this->params[$offset]);
  }
  public function offsetGet($offset) {
    return isset ($this->params[$offset]) ? $this->params[$offset] : NULL;
  }
  public function offsetSet($offset, $value) {
     if (!is_string($offset)) {
      throw new \LogicException("You can only assing to params using specified key.");
     }
     $this->params[$offset] = $value;
  }
  public function offsetUnset($offset) {
    unset ($this->params[$offset]);
  }
}