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

The Archive Base Latest Questions

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

I am trying to store objects in session However, when I do the following,

  • 0

I am trying to store objects in session

However, when I do the following, I don’t get output as expected

Code:

In the session am storing objects like this –

    $oEmployee = new Employee();
    $_SESSION['Employee'] = $oEmployee;

And am trying to print like this –

    print_r($_SESSION['Employee']);
    echo "<br>";
    $oEmployee = new $_SESSION['Employee'];
    print_r($oEmployee);

This is the output I am getting:

    Employee Object
    (
       [m_sFirstName:private] => Sac
       [m_sLastName:private] => Kos
       [m_sPhone:private] => 9876543210
       [m_sEmail:private] => sac@kos.com
       [m_sPassword:private] => password
       [m_iEmployeeId:private] => 1 
    )

    Employee Object
    (
       [m_sFirstName:private] => 
       [m_sLastName:private] => 
       [m_sPhone:private] => 
       [m_sEmail:private] => 
       [m_sPassword:private] => 
    )

Any idea what’s going wrong ?

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

    The problem lies with your line

    $oEmployee = new $_SESSION['Employee'];
    

    PHP casts the value in $_SESSION['Employee'] to string, and then tries to instantiate a class with that name (new). Since you aren’t passing anything to the constructor, an empty object is instantiated.

    What are you trying to do in that line?

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

Sidebar

Related Questions

i want to store a list of objects in session List<ContentQueueLog> inactiveContent = GetInActiveContent(this.userID,
I am very new to processing.org and Java. I am trying to store objects
I am trying to figure out how C and C++ store large objects on
I'm trying to store an xml serialized object in a cookie, but i get
I'm trying to store a password in a file that I'd like to retrieve
How do I get the collection of all Session objects in ASP.NET? (Note that
i'm trying to store some values in the Session from a Handler page ,
I'm trying to store object of Employee in Session (DB Based), When i do
All Rails expert sites say not to store ActiveRecords in the Session. However, I
Possible Duplicate: Can't pass mysqli connection in session in php I'm trying to store

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.