SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Knowledge is key 2 progression Tryst's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Fatal Error When Calling an Attribute of a Session class.

    Hi all,

    I am recieving a fatal error message when attempting to access an attribute of a class which I have used as a session variable. The error message is as follows...

    Fatal error: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition member_class of the object you are trying to operate on was loaded _before_ the session was started in C:\Program Files\Apache Group\Apache\htdocs\MSc\clients.php on line 30
    What I have done was to create a session class based on a user when they have logged in. Now, when I attemp to access a variable of this class on another page I get that error message, but when I access the session class variables on the same page in which the user logged in everything works fine.

    I have the session_start(); statement at the start of the next page, which should automatically pick up the session and its containing class as soon as the page is loaded.

    To instanciate the class I am using the following statement on the login page once the form has been submitted...

    PHP Code:
    $_SESSION['user'] = new member_class(); 
    Now, when I insert the following code...

    PHP Code:
    foreach($_SESSION['user'] as $key => $value)
        echo 
    $key." = ".$value."<br />"
    ...on the next page (not the login page) I get the following output...

    __PHP_Incomplete_Class_Name = member_class
    failed =
    date =
    autoname =
    username = Craig
    token = d3cdff1ac069ab87abe4574d9ca3e128
    logged_in = 1
    Which are the attributes of the session variable class.

    Can anyone see where I am going wrong here

    Thanks

    Tryst

  2. #2
    SitePoint Enthusiast
    Join Date
    Feb 2003
    Location
    vancouver
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You'll need to include the file that contains the class definition before calling session_start().

  3. #3
    Knowledge is key 2 progression Tryst's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, thats done it.

    I was under the impression that the session_start() statement was to be the first statement in a PHP document.

    Thanks

    Tryst


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •