Jump to content

help me find syntax error please


mgph

Recommended Posts

Hi, I'm having this error

Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION

 

It's indicating that the error is at line 6(at the first starting line inside the class), but when I commented that indicated line out, it shows the very next line, again and again.

 

Here are my code

<?php

class Page
{
// attributes
$content;
$title = "Someone Teach Me";
$keywords = "anyone can teach you, something you can learn here";
$buttons = array("Home"		=> "home.php",
				"Contact"	=> "contact.php",
				"Services"	=> "services.php",
				"Site Map"	=> "sitemap.php"
				);


function __set($name,$value)
{
	$this->$name = $value;
}

function Display()
{
	echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n
		<html xmlns=\"http://www.w3.org/1999/xhtml\">\n
		<head>";
	$this->DisplayTitle();
	$this->DisplayKeywords();
	$this->DisplayStyles();
	echo "</head>\n<body>\n";

	$this->DisplayHeader();
	$this->DisplayMenu($this->buttons);
	echo $this->content;
	$this->DisplayFooter();
	echo "</body>\n</html>\n";	
}

function DisplayTitle()
{
	echo "<title>".$this->title."</title>";
}

function DisplayKeywords()
{
	echo "<meta name=\"keywords\" content=\"".$this->keywords."\" />";
}

function DisplayStyles()
{
	echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"_css/backbone.css\" />";
}

function DisplayHeader()
{
	//TODO : add banner & text
	echo "<div id=\"masthead\">masthead</div>";
}

function DisplayMenu($buttons)
{		
    	?>
	<div id="mainNav">
		<ul>
			<li><a href="#" class="active firstList">Home</a></li>
			<li><a href="#">Games</a></li>
			<li><a href="about.html">About</a></li>
			<li><a href="#">References</a></li>
			<li class="lastList"><a href="#">Sitemap</a></li>
		</ul>
	</div>
	<?php
}

function DisplayFooter()
{
	//TODO : add footer here	
}

function IsURLCurrentPage($url)
{
	if (strpos($_SERVER['PHP_SELF'], $url) == false)
		return false;
	else
		return true;
}

}


?>

 

I use it as a template and I get this syntax error when I call from other .php file.

 

please can someone help me find where is it and how to fix it!

thanks in advance

 

Link to comment
https://forums.phpfreaks.com/topic/181739-help-me-find-syntax-error-please/
Share on other sites

you forgot the "var" keyword

 

<?php

class Page
{
   // attributes
   var $content;
   var $title = "Someone Teach Me";
   var $keywords = "anyone can teach you, something you can learn here";
   var $buttons = array("Home"      => "home.php",
               "Contact"   => "contact.php",
               "Services"   => "services.php",
               "Site Map"   => "sitemap.php"
               );
   
   
   function __set($name,$value)
   {
      $this->$name = $value;
   }
   
   function Display()
   {
      echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n
         <html xmlns=\"http://www.w3.org/1999/xhtml\">\n
         <head>";
      $this->DisplayTitle();
      $this->DisplayKeywords();
      $this->DisplayStyles();
      echo "</head>\n<body>\n";
      
      $this->DisplayHeader();
      $this->DisplayMenu($this->buttons);
      echo $this->content;
      $this->DisplayFooter();
      echo "</body>\n</html>\n";   
   }
   
   function DisplayTitle()
   {
      echo "<title>".$this->title."</title>";
   }
   
   function DisplayKeywords()
   {
      echo "<meta name=\"keywords\" content=\"".$this->keywords."\" />";
   }
   
   function DisplayStyles()
   {
      echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"_css/backbone.css\" />";
   }
   
   function DisplayHeader()
   {
      //TODO : add banner & text
      echo "<div id=\"masthead\">masthead</div>";
   }
   
   function DisplayMenu($buttons)
   {      
       ?>
      <div id="mainNav">
         <ul>
            <li><a href="#" class="active firstList">Home</a></li>
            <li><a href="#">Games</a></li>
            <li><a href="about.html">About</a></li>
            <li><a href="#">References</a></li>
            <li class="lastList"><a href="#">Sitemap</a></li>
         </ul>
      </div>
      <?php
   }
   
   function DisplayFooter()
   {
      //TODO : add footer here   
   }
   
   function IsURLCurrentPage($url)
   {
      if (strpos($_SERVER['PHP_SELF'], $url) == false)
         return false;
      else
         return true;
   }
   
}


?>

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.