Page 1 of 1

help me find syntax error pls

Posted: Mon Nov 16, 2009 10:43 am
by mgph
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

Code: Select all

 
<?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

Re: help me find syntax error pls

Posted: Mon Nov 16, 2009 2:50 pm
by requinix
You need "public", "protected", or "private" before each class variable.

Read

Re: help me find syntax error pls

Posted: Mon Nov 16, 2009 7:37 pm
by mgph
tasairis wrote:You need "public", "protected", or "private" before each class variable.

Read
yeah, cool. I thought it's not necessary because default (not explicitly) access mode is public.

It can also with "var $varname" without declaring access mode.

thanks buddy :D