Currently, empty arrays are converted to JavaScript objects by drupal_to_js(). This patch fixes that behavior.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | drupal_to_js_0.patch | 770 bytes | kkaefer |
| drupal_to_js.patch | 756 bytes | kkaefer |
Currently, empty arrays are converted to JavaScript objects by drupal_to_js(). This patch fixes that behavior.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | drupal_to_js_0.patch | 770 bytes | kkaefer |
| drupal_to_js.patch | 756 bytes | kkaefer |
Comments
Comment #1
drummI'd rather see something like count($var) > 0, which would be easier to understand on reading code.
Why shouldn't empty arrays be converted? I'd think an empty array in PHP should be an empty array in JS.
Comment #2
kkaefer commentedThat’s the point. Currently, empty PHP arrays are converted to JavaScript objects (e.g.
{ }) instead of JavaScript arrays ([]).Yes, that one is easier to read. Changed it in the attached patch. If the array length is zero, an empty array instead of an empty object is returned. If the array length is not zero and the indices are sequential numbers, an array is returned. If they are not, an object (hash) is returned.
Comment #3
kkaefer commentedhttp://drupal.org/node/121876 was committed which does exactly the same.