Objects and session

Posted on 2003-03-29
Medium Priority
Last Modified: 2008-03-06
Hi, I'm trying to create an object called Folder and in it I want to keep x Paper objects. Is it possible to keep these objects in a session? So I don't have to load the entire folder everytime I want to load view a page in the folder. I just want to load (from the db) when I'm getting a new Folder

My objects look like this:

class Folder
    var $papers;            // Paper in the folder
        var $myIndex;
        var $myName;           // Category of the folder e.g Examples
        var $myDescription; //Describe whats in the folder
        var $myImage;            //Standard image of folder
     function Folder($name,$description,$image) {
          $this->myIndex      = 0;
          $this->myName     = $name;
          $this->myDescription = $description;
          $this->myImage     = $image;
    // Add a paper to the folder
    function addPaper ($paper) {
        $this->papers[$this->myIndex] = $paper;
    function getPaper ($index) {
         return $this->papers[$index];
    function getName() {
         return $this->myName;
    function getDescription() {
         return $this->myDescription;
    function getImage() {
         return $this->myImage;
    function getSize() {
         return $this->myIndex;

class Paper
     var $myId;       // Id number in the database
     var $myFolder;     // Name of the folder it belongs to (e.g. News, Info)
     var     $myTitle;     // The title of the paper
     var     $myContent;     // The actual "article"
     var     $myImage;     // Name of the image associated with the paper
     function Paper($id,$folder,$title,$content,$image) {
          $this->myId          =     $id;
          $this->myFolder     =     $folder;
          $this->myTitle     =     $title;
          $this->myContent=     $content;
          $this->myImage     =     $image;
     function getId() {
          return $this->myId;
     function getFolder() {
          return $this->myFolder;
     function getTitle() {
          return $this->myTitle;
     function getContent() {
          return $this->myContent;
     function getImage() {
          return $this->myImage;

Question by:Creini
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

bljak earned 300 total points
ID: 8232330
yes, start each page with

$lastYear = new Folder;
//func to execute
//and then
$folder = $lastYear->papers;
//or use ths if session_register() doesn't work (i expirienced problems with php 4.2.2 i think
$_SESSION["folder"] = $folder;

thats it, do not forget to have session_start(); on each next page

hope this helped some further

Expert Comment

ID: 8237729
You must also load the class definition prior to starting the session otherwise php will not understand the data structure when it loads it into memory.


Featured Post

Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question