Lifelesspeople.com

 Forum FAQsForum FAQs  Knowledge BaseKnowledge Base  RulesRules   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   HostingHosting   RegisterRegister 
 DonateDonate   WikiWiki   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

PHP 5 Problems

 
Lifelesspeople.com Forum Index -> Web Architects' Abode
Post new topic   Reply to topic View previous topic :: View next topic  
Author Message
rajasekar
Forum Regular


Joined: 30 May 2004
Posts: 445
Location: Nothing but Net

PostPosted: Thu Oct 18, 2007 7:41 pm    Post subject: PHP 5 Problems Reply with quote

Hi,
Recently my webhost changed the php version from 4.x to 5.2.4 and it makes an error when i used one of my sites. Before i didnt get this error which i am giving below:

Code:
Parse error: syntax error, unexpected T_PRIVATE, expecting ']' in /home/netizen/public_html/elance/forum.php on line 63


The error causing line is the first line in the code given below:

Code:
if ($row[private] == "") {
$msg = str_replace("
","<br>
",$row[message]);
echo $msg;
} else {
echo '<i>Private message for ' . $row[private] . '. <a href="' . $siteurl . '/forum.php?login=' . $row[private] . '&type=viewproj&fid=' . $row[pid] . '">click to view...</a></i><br><br>';
$username = $HTTP_COOKIE_VARS["fusername"];
$tttype = "freelancer";
if ($username == "") {
$username = $HTTP_COOKIE_VARS["busername"];
$tttype = "buyer";
}
if ($row[froom] == $username && $row[acctype] == $tttype || $row[private] == $username && $username !== "" && $row[privatetype] == $tttype || $adminforum == $adminpass) {
$msg = str_replace("
","<br>
",$row[message]);
echo $msg;
}
}


Please help me if there is any php4 to php5 issues. Thank you.[/code]
_________________
Free Online Classifieds - Reach thousands of users world-wide!
[img:0a37bba199]http://www.freelineads.com/banners/banner01.gif[/img:0a37bba199]
Back to top
 
Scott
tutorialtoday.com


Joined: 24 Mar 2005
Posts: 2621
Location: Mississauga, Ontario

PostPosted: Thu Oct 18, 2007 7:48 pm    Post subject: Re: PHP 5 Problems Reply with quote

rajasekar wrote:
Hi,
Recently my webhost changed the php version from 4.x to 5.2.4 and it makes an error when i used one of my sites. Before i didnt get this error which i am giving below:

Code:
Parse error: syntax error, unexpected T_PRIVATE, expecting ']' in /home/netizen/public_html/elance/forum.php on line 63


The error causing line is the first line in the code given below:

Code:
if ($row[private] == "") {
$msg = str_replace("
","<br>
",$row[message]);
echo $msg;
} else {
echo '<i>Private message for ' . $row[private] . '. <a href="' . $siteurl . '/forum.php?login=' . $row[private] . '&type=viewproj&fid=' . $row[pid] . '">click to view...</a></i><br><br>';
$username = $HTTP_COOKIE_VARS["fusername"];
$tttype = "freelancer";
if ($username == "") {
$username = $HTTP_COOKIE_VARS["busername"];
$tttype = "buyer";
}
if ($row[froom] == $username && $row[acctype] == $tttype || $row[private] == $username && $username !== "" && $row[privatetype] == $tttype || $adminforum == $adminpass) {
$msg = str_replace("
","<br>
",$row[message]);
echo $msg;
}
}


Please help me if there is any php4 to php5 issues. Thank you.[/code]


This worked in the PHP 4?

I'm pretty sure the error is because for the variables from the $row array (e.g. $row[private]) need to have quotes around it so $row[private] should be $row['private']. So you need to go through it and change all the $row[private], $row[message], $row[pid] etc. to the same thing except with quotes around them.

I'm surprised this worked in PHP 4, I was under the impression that with arrays you had to have quotes around it unless it was a number or variable.
_________________
Tutorial Management Script - Version 1.4 Released
TutorialToday - Up and running, submit your tutorials!
Linux Tutorials - Coming Soon
Back to top
 
rajasekar
Forum Regular


Joined: 30 May 2004
Posts: 445
Location: Nothing but Net

PostPosted: Thu Oct 18, 2007 9:02 pm    Post subject: Reply with quote

Hi Scott, You simply great. That is the actual problem. When i used $row['message'] the site works well. The array witout quotes are working in php4 but not in php5. Thank you so much Scott Smile
_________________
Free Online Classifieds - Reach thousands of users world-wide!
[img:0a37bba199]http://www.freelineads.com/banners/banner01.gif[/img:0a37bba199]
Back to top
 
krt
...


Joined: 11 Jan 2005
Posts: 4680
Location: Down Under

PostPosted: Fri Oct 19, 2007 1:21 am    Post subject: Reply with quote

When accessing array elements with string keys, always use quotes, even if you are sure it will never become a keyword later on (as in this case, "private" became a keyword in PHP5 for its improved object model so when you upgraded, it assumed you were referring to the keyword "private", not the string). Using quotes is good convention and ensures that people (yourself included) and the interpreter are not confused about whether it is a constant or a string.

This error is a common occurrence, probably helped by people learning off other's crap code, especially in strings where people slack off or don't know about curly braces, e.g.
"interspersing... {$array['element']}"
Back to top
 
LP-SolidRaven
Dictator of the Dump


Joined: 06 Jun 2004
Posts: 7108
Location: The cheese is made out of moon

PostPosted: Fri Oct 19, 2007 9:37 am    Post subject: Reply with quote

Just use $row['private'] instead. Certain names just aren't allowed in variables due to php 5 it's object model. (The most common would be private, public, protected)
_________________
Quote:

<bart416> I just realized something
<bart416> we celebrate the fact that this piece of rock made one rotation around a glowing ball of plasma that is kept together due to its own gravity well
<njsg> HAPPY NEW YEAR
<Easter> ^^
Back to top
 
Display posts from previous:   
Post new topic   Reply to topic    Lifelesspeople.com Forum Index -> Web Architects' Abode All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Home | Hosting | News | Forum | Links | System Status | About | Archive | Donate ]
Powered by phpBB © 2001, 2002 phpBB Group
All trademarks and copyrights on this page are owned by their respective owners. Posts and comments are owned by the poster. Everything else © 2001 - 2007 Lifelesspeople.com