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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:10:43+00:00 2026-05-29T19:10:43+00:00

I am starting to learn PHP and have a decent Java background. I came

  • 0

I am starting to learn PHP and have a decent Java background. I came upon the following coding challenge in the PHP langauge:

I want to be able to encode/decode my PHP classes in JSON format. I have created PHP classes that utilize getter/setter methods for the classes private properties. This caused the native json_encode method to skip skip these properties during encoding. I found the following script which picks up private properties and formats them in a JSON string:

<?php
public function encodeJSON()
{
    foreach ($this as $key => $value)
    {
        $json->$key = $value;
    }
    return json_encode($json);
}
public function decodeJSON($json_str)
{
    $json = json_decode($json_str, 1);
    foreach ($json as $key => $value)
    {
        $this->$key = $value;
    }
}
?>

I studied up on this code and realized how it was generating the strings and objects. Now I would like to push this code into an abstract class, so that I may extend that class and receive this functionality.

The problem is I cannot reference the private properties in the concrete class from the abstract class. My knowledge of Java tells me that I may not be able to do this without specifying an abstract method and forcing each concrete class to implement it. I tried several attempts at using reflection in PHP and passing the concrete class into the constructor of the abstract class. Can anyone point me in the right direction or just tell me if this isn’t possible?

  • 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-29T19:10:46+00:00Added an answer on May 29, 2026 at 7:10 pm

    The concept of private variables is not to be able to see them in delivered classes so it’s correct behavior.

    If you use protected instead your concept should work just fine.

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

Sidebar

Related Questions

I am just starting to research and learn PHP. I have a decent background
I am just starting to learn php, how would I initiate a echo statement
I'm starting to learn about using Memcached with PHP and I was wondering; is
Im starting to learn RoR and i want to make my personal blog in
I am just starting to learn javascript, so I don't have the skills to
I'm starting to learn Python and I've come across generator functions, those that have
I'm a designer (starting to learn PHP/MySQL) and am need in an eCommerce platform
I have been programming procedural PHP for about 8 years, and am finally starting
I am starting to learn everything about security and secure programming. I have always
First, I'm just starting to learn MySQL with PHP. My query copy/paste directly from

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.