Jump to content


Photo

Getting Parse Error on PHP 4.3.3


  • Please log in to reply
6 replies to this topic

#1 jefrat72

jefrat72
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 20 July 2006 - 12:52 PM

I'm trying to learn PHP out of a book, the machine I started on had PHP 5, the server I'm on now has PHP 4.3.3.  So when I run my code I get this error:

"Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/allsys5/public_html/page.php on line 4"

I can not go back to PHP 5, so can anyone help me work out the error in this following code? 


<?php
class Page
{
public $content;
public $title = 'Bob's Book Store';
public $keywords = 'Bob's Book Store, Three Letter Abbreviation,
  some of my best friends are search engines';
public $buttons = array ( 'Home' => 'index.php',
  'Books' => 'Books.php',
  'Helpful Links' => 'helpfullinks.php',
  'Contact Me' => 'feedback.html',
);

// class Page's operations
public function _set($name, $value)
  {
    $this->$name = $value;
  }

public function Display()
  {
    echo "<html>\n<head>\n";
    $this -> DisplayTitle();
    $this -> DisplayKeywords();
    $this -> DisplayStyles();
    echo "</head>\n<body bgcolor='white'>\n";
    $this -> DisplayHeader();
    $this -> DisplayMenu ($this->buttons);
    echo $this->content;
    $this -> DisplayFooter();
    echo "</body>\n</html>\n";
  }

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

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

public function DisplayStyles()
  {
?>
<style>
<!--
    h1 {color:white; font-size:34pt; text-align:center; font-family:TSCu_Comic,arial,sans-serif}
    .menu {color:white; font-size:16pt; text-align:center; font-family:TSCu_Comic,arial,sans-serif; font-weight:bold}
    p {color:steelblue; font-size:12pt; text-align:justify; font-family:arial,sans-serif}
    p.foot {color:black; font-size:15pt; text-align:center; font-family:TSCu_Comic,arial,sans-serif; font-weight:bold}
    a:link,a:visited,a:active {color:red; font-size:16pt}
    a:hover {color:green}
-->
</style>
<?php
  }

public function DisplayHeader()
  {
?>
  <table width="100%" cellpadding="1" cellspacing="0">
  <TR>
    <TD bgcolor="steelblue">
      <h1>Bob's <br> Book Store </br></h1>
    </TD>
  </TR>
  </table>
<?php
  }

public function DisplayMenu($buttons)
  {
    echo "<table width='100%' bgcolor='steelblue' cellpadding='6' cellspacing='4'>\n";
    echo "  <tr>\n";
   

    // calculate button size
    $width = 100/count($buttons);

    foreach ($buttons as $name=>$url)
      {
$this -> DisplayButton($width, $name, $url, !$this->IsURLCurrentPage($url));
      }
   
    echo " </tr>\n";
    echo "</table>\n";
  }

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

public function DisplayButton($width, $name, $url, $active = true)
  {
    if ($active)
    {
      echo "<td width='".htmlentities($width)."%'>
            <a href ='".htmlentities($url)."'>
    <img src='reddot.gif' alt ='".htmlentities($name)."' border ='0' /></a>
    <a href='".htmlentities($url)."'><span class='menu'>$name</span></a></td>";
    }
    else
    {
      echo "<td width='".htmlentities($width)."%'>
    <img src='GREENDOT.GIF'>
    <span class='menu'>$name</span></td>";
    }
  }

public function DisplayFooter()
  {
?>
    <table width="100%" bgcolor="white" cellpadding="2" border="0">
    <TR>     
<p class="foot">Please call me at (123) 555-1234 <br /> or email at                          <a href="feedback.html">test@anywhere.com</a></p>

    </TR>
    </table>
<?php
  }
}
?>

#2 ChaosXero

ChaosXero
  • Members
  • PipPipPip
  • Advanced Member
  • 80 posts

Posted 20 July 2006 - 01:48 PM

public $title = 'Bob's Book Store'; is line 4 and I notice you have Bob's should be bob\'s.  I think that is where the error is.

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 20 July 2006 - 03:52 PM

The main reason is becuase PHP4 doesnt have the same level of OOP as PHP5 has. For example PHP doesnt support public, private or protected keywords when defining methods/objects with PHP4.

I'd recommend you to read the manual for using OOP with PHP4, here.

Also if you are learning. I would strongly suggest you install Apache2.0.x, PHP5.x and MySQL4.x on your local PC/Mac/Laptop. This will allow you to develope and test your PHP scripts locally, offline, rather than using a host.

#4 jefrat72

jefrat72
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 20 July 2006 - 04:23 PM

Also if you are learning. I would strongly suggest you install Apache2.0.x, PHP5.x and MySQL4.x on your local PC/Mac/Laptop. This will allow you to develope and test your PHP scripts locally, offline, rather than using a host.


That's where I ran into the problem.  I wrote this on a PCBSD machine with Apache2.0.x, PHP5.x and MySQL5.x and transferred the code to a host using 4.3.3.  My mistake but now gotta fix it.  Thanks for the link.

#5 jefrat72

jefrat72
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 20 July 2006 - 06:57 PM


I'd recommend you to read the manual for using OOP with PHP4, here.


Just so I'm heading in the right direction it looks like serialize() unserialize() is to PHP4 as Public is to PHP5? 

In other words that's what I need to be using to get this code to work correctly?

#6 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 20 July 2006 - 07:07 PM

No I dont think so. serialize and unserialize only works on strings. It cannot be used when defining a function/variable within a class. For example cannot do this:
serialize function _set($name, $value)
  {
    $this->$name = $value;
  }

The only way to get your code to work is delete any instances of public, private or protected before a function/varible. Then your code should work.

#7 jefrat72

jefrat72
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 20 July 2006 - 08:37 PM

I did get rid of the "Public" and it worked just fine in Firefox and Opera, IE is grumpy about it but I'll figure it out.

Thanks.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users