我目前正在使用 Botman 框架讓我的機(jī)器人讀取 XML 文件。目前,我的機(jī)器人能夠從 XML 文件中獲取數(shù)據(jù)并將其輸出。我在將 XML 文件保存回全局變量時(shí)遇到問(wèn)題(以便稍后可以在代碼中重用)。這是我嘗試執(zhí)行此操作時(shí)收到的當(dāng)前錯(cuò)誤消息:"message": "Serialization of 'SimpleXMLElement' is not allowed","exception": "Exception","file": "C:\\Users\\Jack\\finalyearproject\\gfyp\\gfyp\\vendor\\opis\\closure\\src\\SerializableClosure.php 我這里遇到問(wèn)題:public function nodeTest($xmlFile, $answer){ $this->XMLFile = $xmlFile; ...}這是函數(shù)之前的類(lèi)代碼:class StartConversation extends Conversation{ public $XMLFile; ... public function askForDatabase() { $question = Question::create('Test test test?') ->fallback('Unable to create a new database') ->callbackId('create_database') ->addButtons([ Button::create('Suicide')->value('suic'), Button::create('Self-harm')->value('sh'), ]); $this->ask($question, function (Answer $answer) { $xmlResult = $this->testXMLGrabFunction($answer); if ($answer->getValue() == 'suic') { $this->nodeTest($xmlResult, $answer); } if ($answer->getValue() == 'sh') { $this->nodeTest($xmlResult, $answer); } }); }}這是我最初獲取 XML 文件的類(lèi):class testClass{ function getXMLCategory($categoryName) { $xml = simplexml_load_file('ST-working-age-23-3-20.xml'); if($categoryName == 'suic') { $xml = $xml->node[0]; return $xml; } elseif($categoryName == 'sh') { $xml = $xml->node[1]; return $xml; } else { return null; } }}任何建議都會(huì)很棒 - 謝謝
將 SimpleXMLElement 參數(shù)保存到全局變量
拉丁的傳說(shuō)
2023-07-15 18:25:43