You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When returning an array from a PHP function, exposed to SpiderMonkey, the array is turned into a JSON object, rather than an array. Regardless of whether we are returning an associative or numeric array.
Is there any fix for this available currently or is it expected / correct behaviour?
The text was updated successfully, but these errors were encountered:
The issue is that PHP does not differentiate between associative and numeric arrays internally, the only way to detect it somehow is to scan the array keys and check that none of them are string and that the numeric keys are contiguous. While it is doable, performance on large arrays would be probably quite bad.
The reason is that PHP and Javascript differ in how they work with numeric arrays, see:
Javascript consider arrays as contiguous values, so writing to key 7 implies to keys 0 to 6 exists and those are set to undefined automatically but in PHP no such thing happens:
The reason is once again that PHP does not differentiate between numeric and associative, it just consider the integer 7 as a hash key who just happens to be an integer.
Tbh I guess a 'strict mode' could be added somehow that forces that scan in exchange of processing speed but I'm not sure if it is entirely worth it.
Another solution I had in mind at some point is that if at least 1 numeric key exists, an array is created and string keys are put as property on the array object but I remember that the SpiderMonkey API didn't like that very much.
When returning an array from a PHP function, exposed to SpiderMonkey, the array is turned into a JSON object, rather than an array. Regardless of whether we are returning an associative or numeric array.
Is there any fix for this available currently or is it expected / correct behaviour?
The text was updated successfully, but these errors were encountered: