PHP issue - T_OBJECT_OPERATOR

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

PHP issue - T_OBJECT_OPERATOR

Post 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;<<
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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 "->"
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

also, item(0) might need to be item[0]
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Post 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:
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post 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)
User avatar
seppo0010
Forum Commoner
Posts: 47
Joined: Wed Oct 24, 2007 4:13 pm
Location: Buenos Aires, Argentina

Post 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
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Post 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...
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Post 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...
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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?
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Post 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!
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Are the permissions correct on that XML file?
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Post by Jonah Bron »

I'm not quite sure what that means. It is in the same directory.
Post Reply