Hi, I'm Chris Moyer's Blog.

Stupid Comma!

Normally, when defining a large array in PHP, I'll write it like so:

$foo = array(

    'some_key'  => $val,

    'other_key' => $val2,

    'also_this' => $val3,


Note the comma on the ‘also_this' line. I've gotten into this habit, as it makes it much simpler to later rearrange the order of these elements or add another. As I've been playing with jQuery, I've had cause to create assorted JSON data structures, and wrote a bit of code like so:



        handle: '.handle',

        minValue: 0,

        maxValue: 9000,

        steps: 9,

        stop: slider_slid_callback,



(See the trailing comma?) Well, this works great… in FireFox. In IE?

Line 13
Error: expected identifier, string or number.

Normally I'd complain about IE here, but looking at Introducing Json I see this defintion for a JSON object (doh!):



    { members } 



    pair , members

Back to Blog Home »