title: ArrayAccess Walkthrough with Questions
body: <p>I have some questions about the implementation of implementing <code>ArrayAccess</code> in PHP.</p>
  
  <p>Here is the sample code:</p>
  
  <pre><code>class obj implements arrayaccess {
      private $container = array();
      public function __construct() {
          $this-&gt;container = array(
              "one"   =&gt; 1,
              "two"   =&gt; 2,
              "three" =&gt; 3,
          );
      }
      public function offsetSet($offset, $value) {
          if (is_null($offset)) {
              $this-&gt;container[] = $value;
          } else {
              $this-&gt;container[$offset] = $value;
          }
      }
      public function offsetExists($offset) {
          return isset($this-&gt;container[$offset]);
      }
      public function offsetUnset($offset) {
          unset($this-&gt;container[$offset]);
      }
      public function offsetGet($offset) {
          return isset($this-&gt;container[$offset]) ? $this-&gt;container[$offset] : null;
      }
  }
  </code></pre>
  
  <p><strong>Questions:</strong></p>
  
  <ol>
  <li>I am not asking why we do have to implement <code>ArrayAccess</code> since I am assuming it is special interface that PHP Engine recognizes and calls the implemented inherited functions automatically?</li>
  <li>Why are we declaring the implemented function public? Since I assume they are special functions called automatically. Shouldn't they be private since when calling saying <code>$obj["two"]</code> the functions are not be called from outside.</li>
  <li>Is there a special reason to assign the filled-array in <code>__constructor</code> function? This is the constructor function I know but in this case what kind of help it is being of.</li>
  <li>What's the difference between <code>ArrayAccess</code> and <code>ArrayObject</code>? I am thinking the class I implemented by inheriting the <code>ArrayAccess</code> doesn't support iteration?</li>
  <li>How could we implement object-indexing without implementing <code>ArrayAccess</code>?</li>
  </ol>
  
  <p>Thanks...</p>