Jump to content

T_OBJECT_OPERATOR


drisate

Recommended Posts

Hey guys ... i think i am facing a PHP compatibility issue with an open source script. My server is on PHP4 and this script

 

$result = mysql_query("SELECT * FROM languages WHERE id = ".ucfirst($langdetect)) or die('Query failed get seasons: ' . mysql_error());
    				$detectedlang = mysql_fetch_object($result)->name;
    				$result = mysql_query("SELECT * FROM languages WHERE id = $langid") or die('Query failed get seasons: ' . mysql_error());
    				$enteredlang = mysql_fetch_object($result)->name;
					$errormessage .= "You attempted to enter an $detectedlang overview into the $enteredlang overview field. Please pick the correct language and try again. If the language detected is wrong please come to the forums and let us know.<br/>";

 

is returning

Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /home/betable/public_html/tv/index.php on line 284

 

Can you guys help me rephrase the code above?

Link to comment
Share on other sites

Your a genious genericnumber1 (sarcastic) lol

My question was "Can you guys help me rephrase the code above?" I new it was a compatibility issue hehe

 

Why not just look up the functions it uses via php.net and see which is compatible with php 4 and or 5 and the proper usage for each?

 

mysql_fetch_object

 

You either need to create a class, and put the results in the class or I would suggest just using mysql_fetch_assoc instead.


$detectedlang = mysql_fetch_assoc($result);
$detectedlang = $detectedlang['name'];

Link to comment
Share on other sites

No need to be snippy, I thought it was a good answer :P When you said "a compatibility issue" I assumed you were referring to you conflicting with a script, not that this wasn't your code.

 

I'll repeat what I said: "don't chain the function to the object operator"

 

<?php
$detectedlang = mysql_fetch_object($result)->name;
?>

changed to

<?php
$detectedlang = mysql_fetch_object($result);
$detectedlang = $detectedlang->name;
?>

 

Try to be polite and ask what I mean instead of assuming I didn't answer your question.

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.