Jump to content

unexpected T_OBJECT_OPERATOR error - DOM Parser


Marvin0410

Recommended Posts

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?

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.