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

  • Home
  • SEARCH
  • 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 6111171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:36:00+00:00 2026-05-23T14:36:00+00:00

I am working with doctrine 2 and zend framework 1.11. Public properties are discouraged

  • 0

I am working with doctrine 2 and zend framework 1.11. Public properties are discouraged in Doctrine 2, so I made my entity properties private. However I have just learned that Zend_Json::encode() and json_encode() will not see private / protected properties and thus, not add them in the their output.

Therefore when I use either, and var_dump, I get an empty set eg string(4) “[{}]”.

It turns out I have to write my own function to do the encoding. I was hoping someone has a solution that I can use instead.

  • 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-05-23T14:36:00+00:00Added an answer on May 23, 2026 at 2:36 pm

    The entire point of having member variables as private is to prevent them from being visible to any external code (serialization is an exception because the entire object will need to be restored between sessions).

    Instead of json_encoding this object, you should perhaps create an interface "encodeable" with a method "encode." This will return a json-encoded string of any of the members required by this object. This gives you additional control because instead of serializing all members, you can choose the ones you want to serialize and even perform operations on them to serialize other data.

    Actually you can implement the JsonSerializable interface which works directly with json_encode.

    class MyClass implements \JsonSerializable
    {
        public function jsonSerialize()
        {
            return get_object_vars($this);
        }
    }
    
    $myObject = new MyClass();
    echo json_encode($myObject);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a project that utilizes Zend Framework 1.12 integrated with doctrine
I've been working with Zend Framework (using Doctrine as the ORM) for quite a
I am using Doctrine 2 and Zend Framework 1.11. I have set up my
I am working with Symfony 1.4 and Doctrine. I have a form that has
I'm working on a project with Zend Framework 1.11, Doctrine 2, some Symfony 2
I'm working in the Symfony2 framework and wondering when would one use a Doctrine
i used to have a function defined like this (that is working fine under
I'm working with Doctrine 1.2 in Symfony 1.4 on PHP5.3. I have a database,
I am working on the project that is based on symfony (doctrine) with use
I have recently started to learn using of Doctrine 2.0 framework for PHP. Now

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.