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 8317697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:41:40+00:00 2026-06-08T21:41:40+00:00

I am developing php application in which i am querying database and the generated

  • 0

I am developing php application in which i am querying database and the generated result I am sending back to html client.

Currently I am getting array of objects which I am encoding in JSON using php function json_encode.

But after encoding I am getting null array in my result.

The following structure is before encoding to JSON

 array(2) {
  [0]=>   
      object(ProductComment)#6 (2) {
    ["_productId":"ProductComment":private]=>
    string(1) "1"
    ["_commentArray":"ProductComment":private]=>
    array(2) {
      [0]=>
      array(3) {
        ["comment"]=>
        string(9) "comment 1"
        ["creationDate"]=>
        string(19) "2000-02-02 00:00:00"
        ["userName"]=>
        string(8) "Ashutosh"
      }
      [1]=>
      array(3) {
        ["comment"]=>
        string(13) "comment1 text"
        ["creationDate"]=>
        string(19) "2012-07-31 10:20:27"
        ["userName"]=>
        string(8) "Ashutosh"
      }
    }
  }
  [1]=>
  object(ProductComment)#5 (2) {
    ["_productId":"ProductComment":private]=>
    string(1) "2"
    ["_commentArray":"ProductComment":private]=>
    array(2) {
      [0]=>
      array(3) {
        ["comment"]=>
        string(22) "comment2 product2 text"
        ["creationDate"]=>
        string(19) "2012-07-31 10:48:06"
        ["userName"]=>
        string(8) "Ashutosh"
      }
      [1]=>
      array(3) {
        ["comment"]=>
        string(22) "comment2 product4 text"
        ["creationDate"]=>
        string(19) "2012-07-31 10:48:14"
        ["userName"]=>
        string(8) "Ashutosh"
      }
    }
  }
}

And after encoding it showing null instead of JSON.
Do i need to serialize it?
Anything advice will be appreciable.
Thanking you.

  • 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-08T21:41:43+00:00Added an answer on June 8, 2026 at 9:41 pm

    It looks like all of the properties of “ProductComment” are private, so when it comes to JSON-encoding, you’d get:

    [{}, {}]
    

    Which is basically an array, with two empty objects in it.

    What you need to do is tell PHP which properties can and should be kept when serializing (or json encoding). For that, you want to add the __sleep() magic method to your class: (http://uk.php.net/__sleep)

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

Sidebar

Related Questions

I am developing an iPhone application which logs data in a mySql database. Currently
Okay, I am developing an Application which requires getting sensitive information from a database
I am currently developing an application in PHP in which my server (a dedicated
I am currently developing a small internal PHP application which requires login. The credentials
I am in the middle of developing a PHP social media web application which
I am developing a php application which my customers will download and install on
I am developing a Facebook Iframe application using PHP which opens an RSS feed
I am developing a PHP application which needs a regular expression to replace the
I am developing a PHP/MySQL application which entails processing of CSV files but the
I am developing application in PHP which takes video file. I am giving serverside

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.