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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:30:00+00:00 2026-05-26T09:30:00+00:00

Given this example: class Database { private $host, $database, $username, $password, $type; public $active_connection;

  • 0

Given this example:

class Database
{
    private $host,
            $database, 
            $username, 
            $password,
            $type;

    public $active_connection;

    //Some methods
}


class Page
{
    private $db;


    public function __construct($id)
    {
        // Some code

        $this->db = new Database($id);
    }

    //Some Methods
}


$page = new Page(0);

var_dump($page);

This will output the private variables of Database Object, even though they are marked as private (and so, as I understand it, unusable by the outside world).

My questions are:

  1. Is this a security risk?
  2. Is there a way to effectively hide those variables marked as private?

thanks in advance

EDIT:
In this project, the admin section will provide the ability to create custom PHP scripts to incorporate in the site, as sections. Since this is being developed to a third party entity, my concern is that, for some reason, the costumer inadvertently dumps the $page object (which is, in our code, the main modifiable object) in order to “explore” it.

  • 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-26T09:30:00+00:00Added an answer on May 26, 2026 at 9:30 am

    var_dump() shows them, because it’s special. You can also dig around in private/protected properties using the Reflection API.

    echo $object->_somePrivateVar;

    On the other hand, will not expose _somePrivateVar.

    1) Is it a security issue? Not at all. If you don’t trust the code you’re executing, you’re pretty much boned.

    2) Hide them from what? They’re already hidden according to the data-visibility rules of the class system. But the language is dynamic, and provides some other ways to peek inside. As Leonid just said in his answer, this in an architectural mechanism, not a security feature.

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

Sidebar

Related Questions

This is easier to explain with an example. Given these two classes: public class
This is just an example, but given the following model: class Foo(models.model): bar =
Given this example: <img class=a /> <img /> <img class=a /> <img class=a id=active
Given this example XML file: <doc> <tag> Hello ! </tag> <tag> My name is
Given this example, how would I return the result of the equation rather than
Given the example below, can someone please show me how this could be called?
Given the email address: Jim <jim@example.com> If I try to pass this to MailAddress
I'm trying to solve this problem : http://uva.onlinejudge.org/external/7/732.html . For the given example, they
What is the best method to create a database for the given example model
Given the following example: class AnonymousSession << Struct.new(:location, :preferences) def valid? ... end def

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.