View Full Version : Troubleshooting error:
socalconsult
08-07-2005, 11:54 PM
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /homepages/45/d133225023/htdocs/includes/common.php on line 79
A buddy of mine was working on a website and he made a change to a common page. When he got the error, he attempted to back out his changes but I am not sure he backed out all of the changes. The function on line 79 is as follows:
function PageInit($PageTitle=null, $PageWidth=750) {
global $root;
if($PageTitle!=null) {
$PageTitle = $PageTitle . " | ";
}
echo <<<EOT
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>{$PageTitle}website.com</title>
<meta http-equiv="language" content="english" />
<meta http-equiv="dialect" content="us" />
<meta name="robots" content="all" />
<link rel="stylesheet" href="$root/resources/styles/sitestyles.css" />
<script type="text/javascript"
src="$root/resources/scripts/sitescripts.js"></script>
</head>
<body>
<table cellspacing="0" cellpadding="0" width="100%">
<tr>
<td id="logo">
<a href="$root/"><img src="$root/resources/images/logo.jpg"
style="float:left;vertical-align:middle;border:0px;" /></a>
<div style="float:right;padding-right:10px;">
<ul class="links">
EOT;
if(isset($_SESSION["FirstName"])) {
if($_SESSION["UserType"]=="Administrator") {
echo "<a href=\"", $root, "/admin/\"><li>Administer</a></li>";
}
echo "<a href=\"", $root, "/login/?logout\"><li>Logout ",
$_SESSION["FirstName"], "</a> (<a
href=\"$root/account/\">Account</a>)</li>";
}
else {
echo "<a href=\"", $root, "/login/\"><li>Login</li></a>";
}
echo <<<EOT
<a href="{$root}/cart.php"><li>Shopping Cart</li></a>
</ul>
</div>
</td>
</tr>
</table>
EOT;
Menu($PageWidth);
echo "<td id=\"container\">";
}
Any help in debugging this would be greatly appreciated.
Thanks
marek_mar
08-08-2005, 12:30 AM
I don't recomment using the odd heredoc. It's the couse of your error. The string ends when there is an EOT; and nothing more on the line not even the tab you have. If you delete the tab it'll work.
socalconsult
08-08-2005, 12:37 AM
I don't recomment using the odd heredoc. It's the couse of your error. The string ends when there is an EOT; and nothing more on the line not even the tab you have. If you delete the tab it'll work.
Unfortunately, the EOT is not indented in the code. I actually indented it on this board so that Icould determine where the function in question actually stopped.
marek_mar
08-08-2005, 12:43 AM
Ok, this is why I don't recommend heredoc:
It's also important to realize that the first character before the closing identifier must be a newline as defined by your operating system. This is \r on Macintosh for example.
Fou-Lu
08-08-2005, 03:04 AM
Marek is right, heredoc IMO is the single most useless item in php. Though it looks prettier than a standard escaped string, using this method I find will always cause more problems and headaches than debugging poorly escaped code.
You are better off using a standard echo or creating a string out of it instead. Less of a headache this way.
dumpfi
08-08-2005, 05:54 PM
If you only want to "echo" such a string you can just do:
function PageInit($PageTitle=NULL, $PageWidth=750) {
global $root;
if($PageTitle!=NULL) {
$PageTitle = $PageTitle . ' | ';
}
?>
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title><?php echo $PageTitle; ?>website.com</title>
<meta http-equiv="language" content="english" />
<meta http-equiv="dialect" content="us" />
<meta name="robots" content="all" />
<link rel="stylesheet" href="<?php echo $root; ?>/resources/styles/sitestyles.css" />
<script type="text/javascript"
src="<?php echo $root; ?>/resources/scripts/sitescripts.js"></script>
</head>
<body>
<table cellspacing="0" cellpadding="0" width="100%">
<tr>
<td id="logo">
<a href="<?php echo $root; ?>/"><img src="<?php echo $root; ?>/resources/images/logo.jpg"
style="float:left;vertical-align:middle;border:0px;" /></a>
<div style="float:right;padding-right:10px;">
<ul class="links">
<?php
if(isset($_SESSION['FirstName'])) {
if($_SESSION['UserType']=='Administrator') {
echo '<a href="', $root,'"/admin/"><li>Administer</a></li>';
}
echo '<a href="', $root, '"/login/?logout"><li>Logout ',
$_SESSION['FirstName'], '</a> (<a
href="',$root,'/account/">Account</a>)</li>';
}
else {
echo '<a href="', $root, '"/login/"><li>Login</li></a>';
}
?>
<a href="<?php echo $root; ?>/cart.php"><li>Shopping Cart</li></a>
</ul>
</div>
</td>
</tr>
</table>
<?php
Menu($PageWidth);
echo '<td id="container">';
}
I assume here that you have short_tags = off. Otherwise you must put the '<?xml version="1.0" encoding="iso-8859-1"?>' into a string and echo it out.
dumpfi
socalconsult
08-08-2005, 07:08 PM
So do you all think the only reason we are getting the error is the HEREDOC? We can take that out and try it.
socalconsult
08-08-2005, 09:04 PM
So we commented out the entire function where the error was raised, and get a new error, same message starting at the function above. Here is all of the code above the function in question
<?
define("DBSOCKET", "test");
define("DATABASE", "test");
define("DBUSER", "test");
define("DBPWD", "test");
$root = "";
$connected = false;
session_start();
class DatabaseManager {
var $connection;
function Database() {
$connection=null;
}
function Connect() {
global $connected;
if(!$connected) {
$this->connection=@mysql_connect(DBSOCKET,DBUSER,DBPWD) or
CriticalError(mysql_error());
mysql_select_db(DATABASE, $this->connection) or
CriticalError(mysql_error());
$connected = true;
}
}
function Query($q) {
if($this->connection!=null) {
return mysql_query($q) or CriticalError(mysql_error());
}
}
function Disconnect() {
global $connected;
if($this->connection!=null) {
mysql_close($this->connection);
$this->connection = null;
}
$connected = false;
}
}
function SqlString($str,$trim=false) {
if($trim) return trim(str_replace("'","\'",$str));
return str_replace("'","\'",$str);
}
function IsAdmin() {
return (isset($_SESSION["UserType"]) &&
$_SESSION["UserType"]=="Administrator");
}
function FormatCurrency($a) {
return "$".number_format($a,2,".",",");
}
function ClientMessage($Message,$Url) {
echo <<<EOT
<script type="text/javascript">
alert('{$Message}');
window.location.href('{$Url}');
</script>
EOT;
}
I have gone line by line and I do not see anything else in the file that looks wrong.
marek_mar
08-08-2005, 09:51 PM
If it's not heredoc on your system... It parses correctly on my testserver/debugger.
The method "Database()" is quite useless and the method "Query()" does no always return a value.
socalconsult
08-08-2005, 09:58 PM
Interesting, I am wondering if our host changed something over the weekend. This is frustrating. My knowledge of PHP is not that great but the lines looked fine. I will contact the host.
For my knowledge, how easy is it to install php on a windows machine? Is there a freeware webserver of choice on windows?
I was just trying to help a friend out.
Thanks
Fou-Lu
08-09-2005, 03:42 AM
For your local machine? Its simple, I'd just grab an apache, php, and mysql for windows and go from there. You could use IIS if you have it, but I'd still go with the apache.
Firepages has a site which shows how to install this on a flash stick -> I'd also assume it has a standard installation tutorial. Check that out.
marek_mar
08-09-2005, 03:43 PM
I'd recomend this Tutorial (http://www.philbrodeur.com/tutorials/server2/).
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.