title: PHP: Treat arrays like objects (like in js)
body: <p>In JS you could have something like this:</p>
  
  <pre><code>var a = [1, 2, 3];
  a.myProp = false;
  </code></pre>
  
  <p>This is possible because in js array are actually objects.</p>
  
  <p>What I'm trying to do is to implement the same, but in PHP.</p>
  
  <p>The closest solution I've found is to use the <a href="http://php.net/manual/en/class.arrayobject.php" rel="nofollow">ArrayObject</a> class, but the main problem of this "solution" is that it is object and when you check with <code>is_array</code> or try to use other specific array method it will return false or throw error.</p>
  
  <p>Is there any magic php method like <code>__construct</code> or sth similar for arrays?</p>
  
  <p>In general - I want to add some kind of a flag separated from the array values. For example:</p>
  
  <pre><code>$a = [1, 2, 3];
  
  $a.alreadyIterated = false;
  
  foreach ($a as $item) {
  ...
  }
  
  $a.alreadyIterated = true;
  ...
  
  if (!$a.alreadyIterated) {
      foreach($a as $item) {...}
  }
  </code></pre>