Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7994497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:08:55+00:00 2026-06-04T14:08:55+00:00

Of course, the subject is sort of tricky… I assume json_encode php function works

  • 0

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:

  1. As you can see… the variable $test contains data.

enter image description here

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

It’s definitely me doing something wrong. But… what?

Thanks a lot in advance.

Pedro

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T14:08:56+00:00Added an answer on June 4, 2026 at 2:08 pm

    json_encode only 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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are lots of PHP articles about the subject so is this a PHP
Of course, I can explain it in whole books. But I read a few
Of course we can do this, but is it alright to do so? Are
consider three entities as student, course, subject Below are the associations - student has_many
I went through tons of questions about this subject, but still failed to find
So, I know there's a lot of this subject here and over the Internet.
I did a lot of research on this subject but couldn't find any end
There is a need to provide some sort of interface(save/edit/load) to dynamically generated styles
I'm working on a training course for PHP and I think the mysql syntax
I am planning to attend a one week course on this subject. I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.