我使用工厂来创建一个对象和静态方法来反序列化这个对象:
public static function factory($idText) {
$fetchedObject = self::fetchStoredObject($idText);
return $fetchedObject;
}
private static function fetchStoredObject($idText) {
$fetchedText = DB::select()
->from(table)
->where('idText', '=', $idText)
->execute()->as_array();
if (!empty($fetchedText)) {
return unserialize(base64_decode($fetchedText[0]['txtContent']));
} else {
return NULL;
}
}
对象是这样创建的:
$text = Article::factory($idText);
但我收到以下错误:
unserialize() [<a href='function.unserialize'>function.unserialize</a>]:
Function spl_autoload_call() hasn't defined the class it was called for
在这行fetchStoredObject
方法上:
return unserialize(base64_decode($fetchedText[0]['txtContent']));
为什么会出现这个错误?
编辑
我的班级结构如下:
class Article {
private $phpMorphy;
private $words; //contains instances of class Word
...
private function __construct($idText) {
$this->initPhpMorphy(); // $this->phpMorphy gets reference to the object here
}
public function __sleep() {
return Array(
'rawText',
'idText',
'properties',
'words',
'links'
);
}
public function __wakeup() {
$this->initPhpMorphy();
}
}
该类Word
不包含对 phpMorphy 的引用作为自己的属性,但在其方法中将其用作函数参数。这是序列化字符串的一部分:
" Article words";a:107:{i:0;O:4:"Word":10:{s:5:" * id";O:9:"phpMorphy":7:{s:18:" * storage_factory";O:25:
看来 phpMorphy 是通过与 Word 类的连接进行序列化的。我对吗?