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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:14:12+00:00 2026-06-04T14:14:12+00:00

I am currently working on a large project for a client, and to help

  • 0

I am currently working on a large project for a client, and to help simplify things and make managing sessions easier I have made a session class, this means that if I ever change the way I manage my sessions I can access the structure of the sessions in one file rather then multiple files where a session has been echoed (Such as the users name or the current page)

My class has 3 types of functions setters, getters and unsetters which is kind of self explanatory.

Now in this instance I am setting an error message to the session class directly and then getting the error messages from another class which calls a function from the session within it.

Below are simplified versions on my files showing code I feel is relevent

c_session.php

class session {

    private $instance = 'isntname';
    private $A_user = 'user';
    private $A_page = 'page';
    private $A_message = 'message';

    //Set messages to the session.
    public function set_message($type, $value) {
        $_SESSION[$this->instance][$this->A_message][$type] = $value;
    }

    //Get messages from the session.
    public function get_message() {     
        return $_SESSION[$this->instance][$this->A_message];
    }

    //Unset messages from the session.
    public function unset_message() {
        #unset($_SESSION[$this->instance][$this->A_message]);
    }

}

c_operations.php

class operations {

    //Display all pending messages.
    public function display_pending_messages() {

        if(session::get_message() != null) {
            foreach(session::get_message() as $type => $value) {
                if(strlen($type) != null) {
                    echo '
                        <div class="panel ' . $type . '">
                            ' . $value . '
                            <span class="close" onclick="hide_parent_element(this);">X</span>
                        </div>
                        ';
                }
            }
            session::unset_message();
        }
    }

}

example.php

$session->set_message('confirm', 'THIS IS A CONFIRM');
$session->set_message('error', 'THIS IS AN ERROR');
$session->set_message('notice', 'THIS IS A NOTICE');
$session->set_message('warning', 'THIS IS A WARNING');

var_dump($_SESSION);

$operation->display_pending_messages();

Errors/notices etc received

Notice: Undefined property: operations::$instance in /var/www/_classes/parent_session.php on line 43 
Notice: Undefined property: operations::$A_message in /var/www/_classes/parent_session.php on line 43 
Notice: Undefined index: in /var/www/_classes/parent_session.php on line 43

Line 43 refers to the line return $_SESSION[$this->instance][$this->A_message];

Now if I call get_message() and unset_message() directly via $session->get_message() it works as expected but going through another function in this case $operation->display_pending_messages() it returns the above errors. Obviously this has something to do with the $this-> operator but I’m not to sure on what to do to stop this. I have tried various searches and while finding something similar it wasn’t helpful in this case.

Can someone please explain where I’ve gone wrong and how to fix this?

Thanks in advance.

  • 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-04T14:14:14+00:00Added an answer on June 4, 2026 at 2:14 pm

    In class operations you call your session as static but all your data is in an object.
    The best way is to store in a static, all data of your class session :
    `
    class session {

    private static $instance = 'isntname';
    private static $A_user = 'user';
    private static $A_page = 'page';
    private static $A_message = 'message';
    
    //Set messages to the session.
    public static function set_message($type, $value) {
        $_SESSION[self::instance][self::A_message][$type] = $value;
    }
    
    //Get messages from the session.
    public static function get_message() {     
        return $_SESSION[self::instance][self::A_message];
    }
    

    }

    And so you can call all your functions with session:: in your code, without create object session

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

Sidebar

Related Questions

I'm currently working on a project where we have a large data warehouse which
I am currently working on project where I have to match up a large
Currently in a large c++ project we are working on we have a bunch
Im currently working on a large project and I have built all the different
I'm currently working on a large project which is expected to have a large
I am currently working on a project where I have to manage large sets
I am currently working on a large project and will relatively soon need a
I am currently working on a large project. It is already lunched but the
Our team is currently working on a large project which makes heavy use of
I am currently working on a rather large project with a team distributed across

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.