News for hackers. Stuff that matters.
Re:Union Types have been accepted for PHP 8 by azernik on Saturday November 09, 2019 @08:50PM (#21495886)
JavaScript, by contrast, doesn't have arrays - it just has objects, which can have numerical keys.

  a = []
  a.foo = 'bar' // works!

  b = {}
  b[0] = 42 // also works!
I happen to think these designs are both INSANE, but even if you like them, PHP has no advantage here.
Re:Union Types have been accepted for PHP 8 by roblabla on Saturday November 09, 2019 @09:28PM (#21496025)
I’m pretty sure this is wrong. JS objects and arrays are different. The former will only yield elements from the array itself when iterated on, and has a consistent iteration order, while the later does not.
Re:Union Types have been accepted for PHP 8 by azernik on Sunday November 10, 2019 @02:03AM (#21496830)
That's because arrays happen to override the special [Symbol.iterator] method:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

Arrays are objects of class Array which have special literals, override the toString() method, and update the non-enumerable "length" property on certain operations.

Try calling Object.keys([1, 2, 3]), or even better try Object.getOwnPropertyNames([1, 2, 3])

Re:Union Types have been accepted for PHP 8 by TurningCanadian on Sunday November 10, 2019 @12:49AM (#21496618)
Re:Union Types have been accepted for PHP 8 by mncharity on Saturday November 09, 2019 @10:19PM (#21496190)
Re:Union Types have been accepted for PHP 8 by cutler on Sunday November 10, 2019 @01:00AM (#21496657)
JS arrays are array-like objects. That's the official line anyway.
Re:Union Types have been accepted for PHP 8 by uryga on Saturday November 09, 2019 @08:52PM (#21495898)
so isn't it like PHP, which doesn't have lists, only maps with integer keys?
Re:Union Types have been accepted for PHP 8 by azernik on Sunday November 10, 2019 @02:17AM (#21496872)
With the exception that unlike (I think?) PHP, JS also uses maps (w hich can only have string keys [1]) to implement objects and classes. Hence their being called objects, not maps.

[1] So how do arrays have numerical keys? Well... actually they don't. I was trying to make JS look better than it is in my original comment. Actually, array keys are stringified versions of numbers, and values are automatically cast to string when you put them in indexing braces.

  Object.keys([1, 2])
  --> ["0",  "1"]
As you can imagine, this leads to gotchas when you assume that a JS object can have, say, a date as a key

  b = {}; b[new Date()] = 10;
  Object.keys(b)
  --> [
    "Sat Nov 09 2019 23:15:58 GMT-0800 (Pacific Standard Time)"
  ]