Reputation: 2272
I have a written a code a week back and it was working fine. But today when I chekced it gave me some problem like
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
The part of my code is
$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)
the 182 line in xml2json is
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);
}
here is the pastebin link for var_dump of simpleXMLElement Object
Can someone please help me out that what suddenly happened that its not working.
Thanks
Upvotes: 3
Views: 12600
Reputation: 61
simply add is_object check
if (is_object($simpleXmlElementObject) && get_class($simpleXmlElementObject) == SIMPLE_XML_ELEMENT_PHP_CLASS) {
Upvotes: 6
Reputation: 1708
I would not use, as you are trying to compare against a constant & only using double equals (==) not tripple (===)
if (get_class($simpleXmlElementObject) == SIMPLE_XML_ELEMENT_PHP_CLASS) {
But this instead, something like...
if ($simpleXmlElementObject instanceof SIMPLE_XML_ELEMENT_PHP_CLASS) {
get_class expects the param to be an object & returns a string PHP get_class
Upvotes: 0