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
https://forums.phpfreaks.com/topic/39803-incomplete-objects/
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
https://forums.phpfreaks.com/topic/39803-incomplete-objects/#findComment-192226
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
https://forums.phpfreaks.com/topic/39803-incomplete-objects/#findComment-192231
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
https://forums.phpfreaks.com/topic/39803-incomplete-objects/#findComment-192245
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.