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. Quote Link to comment 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(): ?> Quote Link to comment 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. Quote Link to comment 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(); ?> Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
timbrown Posted February 23, 2007 Author Share Posted February 23, 2007 thanks anyway! Tim. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 23, 2007 Share Posted February 23, 2007 Correct. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.