Closed dave-irvine closed 7 years ago
I think you are having a misunderstanding.
var arr = [];
arr["ham"] = "burgers";
is NOT the same as in PHP. Arrays in JavaScript take numerical indices - and not strings. So in the snipped above, you could've also written:
var arr = [];
arr.ham = "burgers";
...and it'd been the same. Generally, everything in JavaScript is an Object - same applies for arrays. So when you assign a new member to an array, you are not guaranteed that it carries over in Uniter, since only numerical indices are passed. In fact:
Ingwie@Ingwies-MBP.Speedport_W723_V_Typ_A_1_01_012 ~/W/D/DIFM $ node
> var arr = [];
undefined
> arr.foo = "bar";
'bar'
> arr
[ foo: 'bar' ]
> arr.length
0
> for(var i=0; i<arr.length; i++) console.log(i, arr[i])
undefined
... and this conversion might be the case.
So:
With iterating, I mean:
> arr.forEach(console.log.bind(console))
undefined
Nothing happens.
For sure, I know that JS arrays would usually need to be numerically indexed, but just like in #39 where I would like Uniter to convert from a PHP convention that JS doesnt understand, I'd like to be able to send back an array in the format that PHP understands even if JS doesnt.
Alternatively as long as I can pass back an Object with properties and it gets converted to an array on PHP's side, that would work too.
Thanks for reporting this @dave-irvine, it should now be fixed in the latest PHPCore version (v3.17.3+
), where your original code snippet now outputs
array(1) {
["bobs"]=>
string(7) "burgers"
}
Cheers!
Closing as I think the fix referenced above does what we need, but feel free to reopen if needed.
Thanks!