rollbar-php icon indicating copy to clipboard operation
rollbar-php copied to clipboard

Fix incorrect array encoding in config produced by RollbarJsHelper

Open vilius-g opened this issue 6 years ago • 2 comments

When building JS code with RollbarJsHelper and passing configuration parameters that are arrays, those arrays in the final JS output are incorrectly encoded as objects.

vilius-g avatar May 23 '19 09:05 vilius-g

Thanks for taking the time to submit this! I agree; the current code seems buggy.

Digging a little, looks like JSON_FORCE_OBJECT was introduced back in 2017 by @rokob. I think the intent of that change was to ensure the configuration object at the highest level was always an object, but it seems to have neglected the side effect of forcing deep PHP arrays to JSON objects (eg, a configuration of [ "a" => [ ] ] produces {"a":{}} instead of the desired {"a":[]}.

We'll get this in the pipeline for change soon.

bishopb avatar Dec 03 '20 04:12 bishopb

Yeah I was trying to only force the top-level to be an object. PHP never ceases to amaze me. I see now in the docs that there is a user comment about this behavior. Although the main docs don't mention anything about this being applied to the entire structure:

JSON_FORCE_OBJECT (int) Outputs an object rather than an array when a non-associative array is used. Especially useful when the recipient of the output is expecting an object and the array is empty. Available as of PHP 5.3.0.

rokob avatar Dec 04 '20 05:12 rokob

I have fixed merge conflicts.

There seems some issue with CI, but it is possibly one-off as I am unable to reproduce it.

vilius-g avatar Jan 16 '23 18:01 vilius-g