我使用工廠創建對象和靜態方法來解序列化對象的類:反序列化()...功能spl_autoload_call()沒有定義它被稱爲爲
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序列化與connectrion到Word類。我對嗎?
導致問題的類名是phpMorphy。但是該對象的引用存儲在私有變量中。 '_sleep'函數返回的數組中不包含該變量。那麼爲什麼這個變量被序列化呢? –
顯然,這個問題的背景比你第一次告訴我們的要多。你不會簡單地用一個對象序列化某些東西,但是你也可以使用'_sleep' - 可能是'__wakeup'。這些方法可能包含解釋您的問題的代碼,因此請更新您的問題並提供更多信息。 – Sven
另外,與我們分享序列化的字符串(密切關注那裏的機密信息!)。 – Sven