Jump to content

Incomplete Objects


timbrown

Recommended Posts

Hi,

 

I am storing an object in a session variable, but when I call a function of that object I get the following message -

The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "MyClass" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in C:\Documents and Settings\Tim Brown\My Documents\Portal\v4\test\test.php on line 4

 

I don't really want to include the class definition in the code from which the function is called.

 

Link to comment
Share on other sites

Gotta put your session_start() after the class declaration.

 

<?php

session_start():

Class myClass{

}

?>

 

Makes that error. Do this:

 

<?php

Class myClass{

}

session_start():

?>

 

thanks, but I still get that error when calling the function from a second file if it does not include the class definition.

Link to comment
Share on other sites

my files are like this-

 

file1

<?php
class MyClass {

public $thing = "abcdefg";

function tester(){
	echo "tester has been called!";
}
}

session_start();

$x = new MyClass;
$_SESSION["testvar"] = $x;
$_SESSION["testvar"]->tester();
?>

 

 

file 2

<?php
session_start();
$_SESSION["testvar"]->tester();
?>

Link to comment
Share on other sites

"thanks, but I still get that error when calling the function from a second file if it does not include the class definition."

Yes, because the class definition doesn't exist...you need to include it like monk.e says

 

so the function only exists in the definition and there is no way of holding it in the object?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.