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
https://forums.phpfreaks.com/topic/135609-t_object_operator/
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
https://forums.phpfreaks.com/topic/135609-t_object_operator/#findComment-706790
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
https://forums.phpfreaks.com/topic/135609-t_object_operator/#findComment-707002
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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