Arc Forumnew | comments | leaders | submitlogin
1 point by vrk 6163 days ago | link | parent

Are you advocating the style commonly seen in PHP programming?

  $a = array();
  $a[0] = 'foo';
  $a[1] = 'bar';

  /* Fine, $a is an integer-indexed array. */

  $a['another metasyntactic variable'] = 'quux';

  /* Is $a an array (vector) or a hash table? I'm confused. */

  for ($i = 0; $i < 3; $i++) {
     echo $a[$i];
  }

  /* Oops, we looped one too many. No, wait, this prints:
   * foo bar quux
   * Huh?
   */
(PHP automatically assigns as the numerical index the maximum numerical index plus one to the "hash value".)

Hash tables and arrays/vectors are two entirely different concepts. Please do not confuse them with each other.



5 points by dfranke 6163 days ago | link

PHP's brokenness doesn't mean Arc has to imitate it. You'd get a vector up until the $a['another metasyntactic variable'] line, at which point it would turn into a hash table with two integer keys and one string key. Asking for $a[2] would always either return nil or throw an exception regardless of whether it was a hash table or a vector at the time.

-----