gpt4 book ai didi

php - 警告 : get_class() expects parameter 1 to be object

转载 作者:可可西里 更新时间:2023-11-01 00:46:54 26 4
gpt4 key购买 nike

一周前我写了一个代码,它运行良好。但是今天当我检查它时,它给了我一些问题,比如

Warning: get_class() expects parameter 1 to be object, array given in /home/ccc/public_html/horoscope/xml2json.php on line 182

Warning: get_class() expects parameter 1 to be object, string given in /home/ccc/public_html/horoscope/xml2json.php on line 182

Warning: get_class() expects parameter 1 to be object, string given in /home/ccc/public_html/horoscope/xml2json.php on line 182

Warning: get_class() expects parameter 1 to be object, string given in /home/ccc/public_html/horoscope/xml2json.php on line 182

Warning: get_class() expects parameter 1 to be object, string given in /home/ccc/public_html/horoscope/xml2json.php on line 182

我的部分代码是

$currentDate = date("n/j/Y"); 
echo($hdate);
require_once("xml2json.php");

$testXmlFile = "http://www.findyourfate.com/rss/horoscope-astrology-feed.asp?mode=view&todate=$currentDate";
echo($testXmlFile);
$xmlStringContents = file_get_contents($testXmlFile);
$jsonContents = "";
$jsonContents = xml2json::transformXmlStringToJson($xmlStringContents);
$obj =json_decode($jsonContents);
$rows = array();
foreach($obj->rss->channel->item as $item)

xml2json中的182行是

if (get_class($simpleXmlElementObject) == SIMPLE_XML_ELEMENT_PHP_CLASS) {
// Get a copy of the simpleXmlElementObject
$copyOfsimpleXmlElementObject = $simpleXmlElementObject;
// Get the object variables in the SimpleXmlElement object for us to iterate.
$simpleXmlElementObject = get_object_vars($simpleXmlElementObject);
}

这里是 simpleXMLElement 对象的 var_dump 的 pastebin 链接

http://pastebin.com/MPQfdQVx

谁能帮我解决突然发生的问题,它不起作用。

谢谢

最佳答案

只需添加 is_object 检查

if (is_object($simpleXmlElementObject) && get_class($simpleXmlElementObject) == SIMPLE_XML_ELEMENT_PHP_CLASS) {

关于php - 警告 : get_class() expects parameter 1 to be object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16292949/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com