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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:46:54+00:00 2026-06-02T06:46:54+00:00

I have an object that is being thrown into the session array, and I

  • 0

I have an object that is being thrown into the session array, and I want to run a foreach
on the items property.

I can’t seem to access it. I see that it’s private, but I can’t help but wonder why var_dump can show me what the property contains yet I can’t read the data as it throws a fatal error?

I suppose I could do some output buffering and evaluate var_dump as a string if I really have to like this but it seems like there should be a better method. Any ideas how I can access _items?

The object code var_dumped from var_dump($_SESSION['PHPurchaseCart']):

object(PHPurchaseCart)#191 (4) {
  ["_items:private"]=>
  array(2) {
    [0]=>
    object(PHPurchaseCartItem)#190 (6) {
      ["_productId:private"]=>
      string(2) "80"
      ["_quantity:private"]=>
      int(1)
      ["_optionInfo:private"]=>
      string(20) "Monthly Sponsorship "
      ["_priceDifference:private"]=>
      string(3) ".01"
      ["_customFieldInfo:private"]=>
      NULL
      ["_formEntryIds:private"]=>
      array(0) {
      }
    }
    [1]=>
    object(PHPurchaseCartItem)#189 (6) {
      ["_productId:private"]=>
      string(2) "75"
      ["_quantity:private"]=>
      int(1)
      ["_optionInfo:private"]=>
      string(20) "Monthly Sponsorship "
      ["_priceDifference:private"]=>
      string(3) ".02"
      ["_customFieldInfo:private"]=>
      NULL
      ["_formEntryIds:private"]=>
      array(0) {
      }
    }
  }
  ["_promotion:private"]=>
  NULL
  ["_promoStatus:private"]=>
  int(0)
  ["_shippingMethodId:private"]=>
  NULL
}

Ways I’ve tried to access it:

$fun = $_SESSION['PHPurchaseCart'];
var_dump($fun->_items);
exit;

The above throws a fatal error.

  • 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-02T06:47:04+00:00Added an answer on June 2, 2026 at 6:47 am

    That’s the idea of private properties: You can’t access them. You should really not break this concept. If you really want to access such property, mark is as “public” in the original class definition.

    The reason why var_dump can access it is because it is an internal function, and it has the “power” to view the whole object. However, your code doesn’t have that power.

    I wouldn’t recommend it, but if you really need to access a private property, you can use PHP Reflection to achieve it.

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

Sidebar

Related Questions

I have an object that can build itself from an XML string, and write
Ok so I have a JS object that is being POSTed via AJAX to
I have two tables: object that has object_id column and avalues that have object_id
I have an object that represents a food item to order at a restaurant.
I have an object that is mapped to a cookie as a serialized base-64
I have an object that implements IDisposable that is registered with the Windsor Container
I have an object that needs a test if the object data is valid.
I have an object that starts a thread, opens a file, and waits for
I have an object that implements ArrayAccess , Iterator and Countable . That produces
I have an object that has a list of abstract 'aninamls'. i.e. var animals

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.