Jump to content

Getting Parse Error on PHP 4.3.3


jefrat72

Recommended Posts

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 [b]can not[/b] 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
  }
}
?>
Link to comment
Share on other sites

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, [url=http://uk.php.net/manual/en/language.oop.php]here[/url].

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.
Link to comment
Share on other sites

[quote author=wildteen88 link=topic=101236.msg400516#msg400516 date=1153410732]
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.
[/quote]

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.
Link to comment
Share on other sites

[quote author=wildteen88 link=topic=101236.msg400516#msg400516 date=1153410732]

I'd recommend you to read the manual for using OOP with PHP4, [url=http://uk.php.net/manual/en/language.oop.php]here[/url].

[/quote]

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?
Link to comment
Share on other sites

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:
[code]serialize function _set($name, $value)
  {
    $this->$name = $value;
  }[/code]

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.