Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Associative array is not encoded into an object using json_encode. #26

Open
Maxwell175 opened this issue Aug 18, 2018 · 3 comments
Open

Comments

@Maxwell175
Copy link

Maxwell175 commented Aug 18, 2018

Hello,

I found that if an associative array is returned from a foreign function and passed into json_encode, it returns an array instead of an object unless I add JSON_FORCE_OBJECT. This is not the correct behaviour. Associative arrays are supposed to encode into json objects.

@symisc
Copy link
Owner

symisc commented Aug 18, 2018 via email

@Maxwell175
Copy link
Author

Maxwell175 commented Aug 18, 2018

This is a link to a php tutorial for this kind of thing: https://www.dyn-web.com/tutorials/php-js/json/array.php#assoc

See this online php sandbox: http://sandbox.onlinephpfunctions.com/code/1d75b0a84813ebb107646563f5935d4aa524f37d

The result is the same as far back as version 5.2.16 (released 16 December 2010), which seems to be the first version that has json_encode.

@Maxwell175
Copy link
Author

Here is a sample that shows what JSON_FORCE_OBJECT is supposed to do:
http://sandbox.onlinephpfunctions.com/code/e03e7d0c95e0a6528bc63fbc732fabeeed2baae4

Maxwell175 added a commit to Maxwell175/SSNFS that referenced this issue Aug 24, 2018
This will be used in the coming feature.

Upstream issue: symisc/PH7#26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants