php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #6700 Problem With Objects as Session Variables
Submitted: 2000-09-12 23:01 UTC Modified: 2000-09-13 18:21 UTC
From: dkm at cwcom dot net Assigned: joey (profile)
Status: Closed Package: Session related
PHP Version: 4.0.2 OS: RH Linux 6.2
Private report: No CVE-ID: None
 [2000-09-12 23:01 UTC] dkm at cwcom dot net
My problem appears to be the same as Bug id #6604 which, as yet, has received no feedback.

While simple variables work fine, I receive the following error with the example scripts below:

"Fatal error: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition person of the object you are trying to operate on was loaded _before_ the session was started in /usr2/www/test/sessions/second.php on line 6"

If I use $ser_aperson = serialize($aperson) in first.php and unser_aperson = unserialize($ser_aperson) then unser_aperson->print_details() works fine.  I understand that serialization of objects should be handled automatically by the session module.  

person.inc
==========
class person
{
  var $first_name = "John";
  var $surname = "Smith";

  function display_details()
  {
    print("First Name: ". $this->first_name. "<br>");
    print("Surname: ". $this->surname. "<br>");
  }
}

first.php
=========
<?
  require("person.inc");
  session_start();
  session_register(aperson);
  $aperson = new person;
?>
<html>
<head>
  <title>First</title>
</head>
<body>
  <a href="second.php">Second</a>
</body>
</html>

second.php
==========
<?
  session_start();
?>
<html>
<head>
  <title>Second</title>
</head>
<body>
  <? $aperson->display_details(); ?>
</body>
</html

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-09-12 23:30 UTC] dkm at cwcom dot net
I missed out the require statement in second.php.  The actual script is:

second.php
==========
<?
  require("person.inc");
  session_start();
?>
<html>
<head>
  <title>Second</title>
</head>
<body>
  <? $aperson->display_details(); ?>
</body>
</html




 [2000-09-12 23:31 UTC] joey@php.net
Your problem is stated right in the error message.
PHP needs the class definition to be loaded in order
to reconstruct the object.

In other words:
sencond.php needs person.inc, also
 [2000-09-12 23:36 UTC] joey@php.net
Ooops. Looks like we were editing at the same time! :)
I'll look into this.
 [2000-09-12 23:37 UTC] joey@php.net
Assigning to me unless someone has an answer ready.
 [2000-09-13 18:17 UTC] dkm at cwcom dot net
I' ve found the problem.  My php.ini had "session.auto_start = On" which was causing the session to be started before the class definition was available. So the problem was stated in the error message after all.  Perhaps there is an argument for insisting that users always post their php.ini, or at least the parts that are relevant to their problem.

Thanks for your help.

David Marley
 [2000-09-13 18:21 UTC] sniper@php.net
Closed. (config error by user)

--Jani
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun May 11 05:01:28 2025 UTC