Of course, the subject is sort of tricky… I assume json_encode php function works perfectly.
But there must be something wrong on what I am doing.
I have a variable in my PHP program that actually contains data. Sort of structured data, as it is an object variable with all its attributes set properly.
But, magically, when I apply json_encode to that variable, it just doesn’t "fills" the json object.
See the case below:
- As you can see… the variable $test contains data.

- Now, putting the focus on the whole json_encoder($test) thing, it just doesn’t fills the "test" {} part of the json object.

It’s definitely me doing something wrong. But… what?
Thanks a lot in advance.
Pedro
json_encodeonly works with public properties, it cannot take the private or protected attributes of an object and form a JSON representation without any help.To serialize an object with all of its properties, you need to manually implement a function to do so. The official PHP documentation has a good example on how to do this here