timbrown Posted February 23, 2007 Share Posted February 23, 2007 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 More sharing options...
Jessica Posted February 23, 2007 Share Posted February 23, 2007 Gotta put your session_start() after the class declaration. <?php session_start(): Class myClass{ } ?> Makes that error. Do this: <?php Class myClass{ } session_start(): ?> Link to comment https://forums.phpfreaks.com/topic/39803-incomplete-objects/#findComment-192220 Share on other sites More sharing options...
timbrown Posted February 23, 2007 Author Share Posted February 23, 2007 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 More sharing options...
timbrown Posted February 23, 2007 Author Share Posted February 23, 2007 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 More sharing options...
monk.e.boy Posted February 23, 2007 Share Posted February 23, 2007 I think in file 2 you need to include_once the file with the class in it. PHP doesn't know the class definition. I think. Try putting the class in a separate file and include it in both file1 and file2 monk.e.boy Link to comment https://forums.phpfreaks.com/topic/39803-incomplete-objects/#findComment-192236 Share on other sites More sharing options...
Jessica Posted February 23, 2007 Share Posted February 23, 2007 "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 Link to comment https://forums.phpfreaks.com/topic/39803-incomplete-objects/#findComment-192240 Share on other sites More sharing options...
timbrown Posted February 23, 2007 Author Share Posted February 23, 2007 "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 More sharing options...
timbrown Posted February 23, 2007 Author Share Posted February 23, 2007 thanks anyway! Tim. Link to comment https://forums.phpfreaks.com/topic/39803-incomplete-objects/#findComment-192250 Share on other sites More sharing options...
Jessica Posted February 23, 2007 Share Posted February 23, 2007 Correct. Link to comment https://forums.phpfreaks.com/topic/39803-incomplete-objects/#findComment-192255 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.