| Author |
Message |
rajasekar Forum Regular
Joined: 30 May 2004 Posts: 445 Location: Nothing but Net
|
Posted: Thu Oct 18, 2007 7:41 pm Post subject: PHP 5 Problems |
|
|
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
|
Posted: Thu Oct 18, 2007 7:48 pm Post subject: Re: PHP 5 Problems |
|
|
| 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
|
|
| Back to top |
|
| |
krt ...

Joined: 11 Jan 2005 Posts: 4680 Location: Down Under
|
Posted: Fri Oct 19, 2007 1:21 am Post subject: |
|
|
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
|
Posted: Fri Oct 19, 2007 9:37 am Post subject: |
|
|
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 |
|
| |
|
|
|