Marvin0410 Posted April 20, 2011 Share Posted April 20, 2011 Hello all, I have here some PHP code that was working fine under my installation of XAMPP (it has PHP 5). When I moved the following code to my web hosting site, 1&1, it threw up the error you see in the subject field. I attempted to create a new htaccess file in the same directory as my website files to force PHP 5, but I still get the same error. Any ideas on how else I can parse the XML? My code is as follows: //get ALL instances of wanted element(s) $titles = $item->getElementsByTagName('title'); $dates = $item->getElementsByTagName('pubDate'); $descriptions = $item ->getElementsByTagName('description'); //formatting $content = (' <ul class ="blog_entry"> <li class="title_entry"> '.$titles->item(0)->nodeValue. '</li> <li class="date_entry"> Posted on '.date("M d, Y H:i",strtotime($dates->item(0)->nodeValue)). '</li> <br> <li class="description_entry"> '.$descriptions->item(0)->nodeValue. '</li> </ul> '); echo $content; } Personally, I think it's a problem with the nodeValue, since apparently the PHP 5 push doesn't seem to work. Any other way I could reference the XML values I get? Quote Link to comment https://forums.phpfreaks.com/topic/234212-unexpected-t_object_operator-error-dom-parser/ Share on other sites More sharing options...
betterphp Posted April 21, 2011 Share Posted April 21, 2011 what php version is your host using ? Quote Link to comment https://forums.phpfreaks.com/topic/234212-unexpected-t_object_operator-error-dom-parser/#findComment-1204284 Share on other sites More sharing options...
Marvin0410 Posted April 21, 2011 Author Share Posted April 21, 2011 They're using PHP4, but I tried modifying the htaccess file to force PHP5...it still gave the same error...maybe it's their specific configuration of PHP, I'm not sure... Maybe I need to find something other than the DOMParser to parse this XML... Quote Link to comment https://forums.phpfreaks.com/topic/234212-unexpected-t_object_operator-error-dom-parser/#findComment-1204291 Share on other sites More sharing options...
requinix Posted April 21, 2011 Share Posted April 21, 2011 PHP 4 doesn't support function calls chained with object operators. In other words, $x = foo()->bar; is invalid. Use a temporary variable. $temp = foo(); $x = $temp->bar; Quote Link to comment https://forums.phpfreaks.com/topic/234212-unexpected-t_object_operator-error-dom-parser/#findComment-1204292 Share on other sites More sharing options...
Marvin0410 Posted April 21, 2011 Author Share Posted April 21, 2011 So instead of directly referencing $titles->item(0)->nodeValue, I can do something like, $foo2 = item(0); $foo = $titles->$foo2->nodeValue; Despite the fact that item(0) references an object in an array (I think)? If so, I could try that... Quote Link to comment https://forums.phpfreaks.com/topic/234212-unexpected-t_object_operator-error-dom-parser/#findComment-1204294 Share on other sites More sharing options...
requinix Posted April 21, 2011 Share Posted April 21, 2011 Yes. Despite the fact that item(0) references an object in an array 1. An array as a concept, yes. If that's DOM then the "item" function belongs to a DOMNodeList, and calling item() returns a DOMNode. Whether there are arrays behind the scenes or what isn't important. 2. There are two basic steps to executing code for every interpreted programming language. First is to build a series of tokens which convert the symbols you type into individual pieces of data that the interpreter can handle. Like converting every thing into one character: "foo()->bar" might translate to "FAN", where 'F' represents a function call, 'A' represents the arrow operator (->), and 'N' represents a name of something. Next comes converting those tokens into real actions: calling the "foo" function, treating the returned value as an object, and searching for its "bar" member. For all this to work there have to be a set of rules about what tokens are allowed where. PHP 4 simply did not support the "FA" combination. Could have been oversight on the PHP developer(s) side, or maybe the code to allow such a thing was too complicated at the time. Whatever the reason, "FA" was not a valid series of tokens. (In PHP 5 they allowed it.) So while accessing a member of an object, which itself was returned from a function, is a perfectly valid thing to do, PHP 4 wouldn't let you do both parts at the same time. Quote Link to comment https://forums.phpfreaks.com/topic/234212-unexpected-t_object_operator-error-dom-parser/#findComment-1204364 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.