I have a custom class in PHP. If I serialize the class and save it to a text file, I can't unserialize it later in another php file. When I try to call the class functions on the object I get
Call to a member function [functioname()] on a non-object...
I do include the class in both php files.
PHP File 1:
$myobject = new myclass();
$temp = serialize($myobject);
file_put_contents('serializetest.txt', $temp);
PHP File 2:
$s = file_get_contents('serializetest.txt');
$newobject = unserialize($s);
Is there some reason why a serialized class would unserialize properly?
Update
If I create an object and use it's main function I can unserialize the unrelated saved object. The class searches for criminal cases. Even though the two objects are entirely different, once I create and use the new object I can suddenly unserialize saved past objects. i.e. The below works but if I removed the first 3 lines of code it wouldn't.
$tempcase = new Expungement();
$tempcase->searchCase('4B02305986','Public',true,false);
echo "Case Number 1: " . $tempcase->caseno;
$s = file_get_contents('serializetest.txt');
echo "Serialized Data: " . $s;
$newcase = unserialize($s);
echo "Case Number 2: " . $newcase->caseno;
myclass
is. - Devon$newobject
to see what is contains? - Devon$s
. - Devon