Page 1 of 2

PHP issue - T_OBJECT_OPERATOR

Posted: Tue Nov 13, 2007 2:12 pm
by Jonah Bron
Hi,

I have some PHP code that works perfectly on my localhost (PHP5) but produces an error on my server (also PHP5):

Parse error: parse error, unexpected T_OBJECT_OPERATOR in /doc.php on line 60

This page is included by another page, which is included by another page:

mainpage ->include secondpage
secondpage ->include doc.php

Soooo, two questions. Why does it not work on my server, and, more importantly: what is a T_OBJECT_OPERATOR?

Help much appreciated.

Here is an excerpt of the code:

Code: Select all

57 | $pages = $doc->getElementsByTagName( "page" );
58 | foreach( $pages as $page ){
59 | $names = $page->getElementsByTagName( "name" );
>>60 | $name = $names->item(0)->nodeValue;<<

Posted: Tue Nov 13, 2007 2:19 pm
by s.dot
Do you have a ?> (closing tag) at the end of your first include?
If so, check that it doesn't have any spaces or new lines after it.. (or just remove it).

I believe T_OBJECT_OPERATOR is the "->"

Posted: Tue Nov 13, 2007 2:22 pm
by s.dot
also, item(0) might need to be item[0]

Posted: Tue Nov 13, 2007 3:17 pm
by Jonah Bron
Thanks for the reply. No, it isn't item[0], because, A, I did some research on php.net, and it is in brackets, and B, if I do set it to item[0], it gives me other errors. (F.Y.I., this is an XML hookup)

Why does it work on my localhost? I have almost the exact same thing on my server. I have the same include network on my computer, so everything is under the exact same conditions on the server, and on my computer. But, no! I'll never give in! You killed... er, I mean, nothing. Never mind. :wink:

Posted: Tue Nov 13, 2007 3:51 pm
by Zoxive
PHPyoungster wrote:.. No, it isn't item[0], because, A, I did some research on php.net, and it is in brackets.....
Just FYI..

[] are Box Brackets or Square Brackets.

() Are Parentheses or Round Brackets. (Commonly called Parentheses)

Posted: Tue Nov 13, 2007 4:03 pm
by seppo0010
I don't want to be rude, but that's the error I'm getting using that code on PHP 4... are you sure you are running PHP 5? Also it is a Parse Error...... It really really really seems like PHP 4

Posted: Tue Nov 13, 2007 4:45 pm
by Jonah Bron
Thanks Zoxive. Never can learn too many technical terms :)

This is strange, seppo0010. (no rudness there. :) Just more help) I had my server update to PHP5 just yesterday. I have an idea: I'll test a php function that I know doesn't work in PHP4. Know of any? I'm thinking...

Posted: Tue Nov 13, 2007 4:55 pm
by Jonah Bron
Okay,

I re-uploaded another PHP/XML doc that works on PHP5, and has errors on PHP4. It has the same errors. Sooo, aparently, there was some sort of issue in the PHP update on my server. Sorry for the bother :oops:

I'll have to ask about that...

Posted: Tue Nov 13, 2007 5:10 pm
by RobertGonzalez
phpinfo() may be useful in a situation like this. If nothing else, it will confirm your settings.

Also, what are your error reporting levels for both servers?

Posted: Tue Nov 13, 2007 6:54 pm
by Jonah Bron
uh-duh! Why didn't I think of it before? phpinfo(). Thanks. Settings on my comp. are E_ALL, but not sure on remote server.

Thanks.

Posted: Tue Nov 13, 2007 11:15 pm
by RobertGonzalez
Another thing you could try is setting error_reporting to E_STRICT. That is a PHP 5 + constant so if you try to use it on PHP 4 you are more than likely going to get an error.

Posted: Wed Nov 14, 2007 9:59 am
by Jonah Bron
Yup, everah. I used phpinfo(), and it is still on php 4. I wonder what happened :nono:

Thanks again for your help!

Posted: Tue Nov 20, 2007 5:37 pm
by Jonah Bron
Okay, I descovered from my server that I have to have files with the extension of php5, for php5 to work. I am getting errors still, and I was just wonder what they mean:

Warning: DOMDocument::load() [function.DOMDocument-load]: Start tag expected, '<' not found in /blog/xml_doc.xml, line: 2 in /index.php5 on line 3

Fatal error: Call to a member function getElementsByTagName() on a non-object in /index.php5 on line 6

This is the php5 doc:

Code: Select all

<?php
$xml = new DOMDocument();
$xml->load('xml_doc.xml');
$xml->formatOutput = true;
$root = $xml->documentElement;
$counts = $root->getElementsByTagName('home');

foreach ($counts as $count){
  $count->nodeValue += 1;
  echo $count->nodeValue;
}
$xml->save('xml_doc.xml');
$xml->saveXML();
?>
and this is the xml file:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<node>
<sub_node>4</sub_node>
</node>
Yes, it still works on my computer.

Posted: Tue Nov 20, 2007 5:40 pm
by RobertGonzalez
Are the permissions correct on that XML file?

Posted: Tue Nov 20, 2007 5:44 pm
by Jonah Bron
I'm not quite sure what that means. It is in the same directory.